Linux 中ln 命令-n 参数的含义
参考:
https://superuser.com/questions/645842/how-to-overwrite-a-symbolic-link-of-a-directory
参考的文章中已经说的很清楚了,我稍微补充一下,引用原帖的例子
The proper way to do this is to use the -n, --no-dereference
option like so.
$ ln -snf foo2 bar
This causes ln
to treat the existing symlink as a file. Otherwise, it dereferences bar
to foo1
, descends into foo1
and uses the original TARGET
name as the LINK_NAME
and that's why you end up with a symlink to foo2
being created inside the foo1
directory. The manpage on ln
states the following...
-n, --no-dereferencetreat LINK_NAME as a normal file if it is a symbolic link to adirectory
Below is the shell output on my Arch Linux desktop with version 8.21 of ln
with and without the --no-dereference
option, I got the same results you did without the --no-dereference
option, but using the --no-dereference
option it worked as expected.
$ mkdir foo1 foo2
$ ln -s foo1 bar
$ ls -l barlrwxrwxrwx 1 drew users 4 Sep 17 12:51 bar -> foo1
$ ln -sf foo2 bar
$ ls -l barlrwxrwxrwx 1 drew users 4 Sep 17 12:51 bar -> foo1
$ ls -l foo1total 0lrwxrwxrwx 1 drew users 4 Sep 17 12:51 foo2 -> foo2
$ ln -snf foo2 bar
$ ls -l barlrwxrwxrwx 1 drew users 4 Sep 17 12:52 bar -> foo2
简单来说-n 就是让已存在的符号链接(即软连接)不被转义解析,就相当于$var 原样输出而不是取其被赋予的值。
man ln 显示了创建link 的四种方式
NAME
ln - make links between files
SYNOPSIS
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
ln [OPTION]... TARGET (2nd form)
ln [OPTION]... TARGET... DIRECTORY (3rd form)
ln [OPTION]... -t DIRECTORY TARGET... (4th form)
DESCRIPTION
In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd
form, create a link to TARGET in the current directory. In the 3rd and 4th forms,
create links to each TARGET in DIRECTORY. Create hard links by default, symbolic
links with --symbolic. By default, each destination (name of new link) should not
already exist. When creating hard links, each TARGET must exist. Symbolic links
can hold arbitrary text; if later resolved, a relative link is interpreted in
relation to its parent directory.
Mandatory arguments to long options are mandatory for short options too.
如果恰巧相被覆盖的软连接指向的是一个目录的话,不加-n 参数,则相当于第二种创建方法,即在某目录下创建软连接文件。
Linux 中ln 命令-n 参数的含义相关推荐
- linux 磁盘科隆,Linux中ln命令用法详解(硬链接)
硬连接指向的是节点(inode),是已存在文件的另一个名字,修改其中一个,与其连接的文件同时被修改;对硬链接文件进行读写和删除操作时候,效果和符号链接相同.但如果我们删除硬链接文件的源文件,硬链接文件 ...
- linux 中解析命令行参数 (getopt_long用法)
getopt_long支持长选项的命令行解析,使用man getopt_long,得到其声明如下: #include <getopt.h> int getopt_long ...
- ln -s命令 linux_浅谈linux中ln命令,附带案例
链接类型: 1.硬链接 通过索引节点来进行连接.在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index).多个文件名指向同一索引节点是 ...
- linux 中的 ln 命令,Linux中ln命令的用法以及分析
在ubuntu用也有类似于windows中快捷方式这种类型的东西,即链接.这里一般使用ln命令来执行得到,ln命令用法简单,但是与windows不同,这里有硬链接和软链接两种类型的链接.在介绍两种链接 ...
- linux中du命令参数的用法,linux中du命令参数及df命令和dd命令介绍
本文详细介绍了linux中du命令参数及df命令和dd命令的使用方法,并对之进行了举例说明. linux中df命令参数 linux中df命令参数功能:检查文件系统的磁盘空间占用情况.可以利用该命令来获 ...
- Linux中 C++ main函数参数argc和argv含义及用法
Linux中 C++ main函数参数argc和argv含义及用法 简介 argc 是 argument count的缩写,表示传入main函数的参数个数: argv 是 argument vecto ...
- linux中mkdir命令含义,Linux中mkdir命令详解
Linux中mkdir命令详解 linux mkdir用来创建目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1. 新建一个文件夹 one 2. 新建三个 ...
- linux中systemctl命令理解以及.service文件参数解析
linux中systemctl命令理解以及.service文件参数解析 一.systemctl介绍 二.利用.service文件管理程序的步骤 三..service配置文件参数详解 1. Unit 2 ...
- linux cp -r 参数,Linux系统中cp命令的参数及用法详解
Linux系统中cp命令主要是用来复制文件或者目录.下面由学习啦小编为大家整理了Linux系统中cp命令的参数及用法详解的相关知识,希望对大家有帮助! Linux系统中cp命令的参数及用法详解:参数说 ...
最新文章
- 简单使用DESeq2/EdgeR做差异分析
- Tensorflow 变量的共享
- python估计物体角度
- c语言地震子波6,地震子波反褶积程序
- StyleGAN v2:对StyleGAN v1的思考与改进
- h文件中报错 unterminated conditional directive的原因
- java 挂起_Java 6 JVM挂起
- 在线编程JavaScript
- 数字电视输出标准规范和BT601/BT709/BT2020色域转换方法资料整理
- 2020微博热点数据简析
- 数据分析36计(27):分析师与用户研究员,玩转定量研究和定性研究,落地研究结论...
- 关于 attiny 85 http://digistump.com/package_digistump_index.json下载错误
- 怎么用计算机编写圆的面积,圆面积计算器.doc
- linux-网卡名字说明_基本网络配置_修改MTU值
- php话费充值接口对接,基于PHP的聚合数据手机话费充值API调用代码示例
- 华为交换机审计配置_华为交换机AAA配置管理.doc
- C语言程序设计学习笔记:P3-判断
- 简单了解下DDOS产业
- 爬虫_urllib2库的使用
- 使用Python:XPath提取猫眼电影