代码编织梦想

参考:

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-dereference
       treat  LINK_NAME  as a normal file if it is a symbolic link to a
       directory

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 bar
  lrwxrwxrwx 1 drew users 4 Sep 17 12:51 bar -> foo1
$ ln -sf foo2 bar
$ ls -l bar
  lrwxrwxrwx 1 drew users 4 Sep 17 12:51 bar -> foo1
$ ls -l foo1
  total 0
  lrwxrwxrwx 1 drew users 4 Sep 17 12:51 foo2 -> foo2
$ ln -snf foo2 bar
$ ls -l bar
  lrwxrwxrwx 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 参数,则相当于第二种创建方法,即在某目录下创建软连接文件。

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yoshubom/article/details/90205440

linux echo命令介绍及-n、-e参数详解_dumb_man的博客-爱代码爱编程_echo 参数

echo命令用于在shell中打印shell变量的值,或者直接输出指定的字符串。linux的echo命令,在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的,因此有必要了解下echo的用法echo命令的功能是在显示器上显示一段文字,一般起到一个提示的作 用。 语法 echo(选项)(参数)选项 -e:激活转义字符。

ln命令详解_行者三个石的博客-爱代码爱编程_ln 命令

Linux文件系统中,有所谓的链接(link),我们可以将其视为档案的别名,而链接又可分为两种 : 硬链接(hard link)与软链接(symbolic link),硬链接的意思是一个文件可以有多个名称,而软链接的方式则是产生一个特殊的文件,该文件的内容是指向另一个文件的位置。硬链接是存在同一个文件系统中,而软链接却可以跨越不同的文件系统。 软链接:

linux命令--ln软连接,硬链接_冰夫子的博客-爱代码爱编程_ln 软连接

ln:英文名link,链接的意思。 Linux 系统中有软链接和硬链接两种特殊的“文件”。 硬链接特征: 1) 硬链接文件跟源文件拥有相同的i(inode)节点和存储block块, 它们可以看作是同一个文件。 2) 可通过i节点进行识别(i节点相同)。 3) 链接文件和源文件必须在相同的分区,不能跨分区。 3) 不能针对目录创建硬链接。

linux ln(link) 命令详解_wangrusheng5200的博客-爱代码爱编程

这是linux中一个非常重要命令,请大家一定要熟悉。它的功能是为某一个文件或目录在另外一个位置建立一个同步的链接,类似Windows下的超级链接。 这个命令最常用的参数是-s,具体用法是:sudo ln -s 源文件 目标文件 当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录放上该文

linux命令2_lalala323的博客-爱代码爱编程

file 辨识文件类型和编码格式 参数含义文件名查看指定文件的类型信息-b 文件名查看指定文件的类型信息但是不输出文件名-i 文件名输出文件的MIME类型字符串-F “符号” 文件名将输出的格式文件名 符号 文件类型和编码

linux 命令_n_saber的博客-爱代码爱编程_linux的-n

1. 复制 cp 复制文件到目录/或者到指定的文件(重命名) cp file /root/ 将file1 复制到root目录下 cp file1 /root/file2  将file2 复制到root 下,并命名为file2 复制目录 cp [options] source_dir dest_dir   将源目录复制到目标目录 options:

shell脚本中的-n什么意思?-爱代码爱编程

  一、字符串运算符 下表列出了常用的字符串运算符,假定变量 a 为 "abc",变量 b 为 "efg": 运算符说明举例=检测两个字符串是否相等,相等返回 true。[ $a = $b ] 返回 false。!=检测两个字符串是否相等,不相等返回 true。[ $a != $b ] 返回 true。-z检测字符串长度是否为0,为0返回 true。

linux中代码挂上n,Linux系统常用命令nl详解(示例代码)-爱代码爱编程

nl命令在linux系统中用来计算文件中行号。nl可以将输出的文件内容自动的加上行号!其默认的结果与cat -n有点不太一样,nl可以将行号做比较多的显示设计,包括位数与是否自动补齐0等等的功能。本文和大家分享的主要是linux中nl命令的相关用法,希望对大家学习linux有所帮助。 1.命令格式: nl [选项]… [文件]… 2.命令参数:

Linux笔记(11)Linux中cat命令与nl,-n的使用-爱代码爱编程

cat :显示文件的全部内容 cat nl 空行不给编号 cat -n 空行也编号 cat + -n (其中-n=–number) [root@sc-chenlu lianxi]# cat -n passwd 1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bin:/bin:/sbin/n

【linux命令】深入理解sed中的-n选项和-p选项的用法_云川之下的博客-爱代码爱编程

首先介绍一下sed命令这两个选项的意思: -n选项:只显示匹配处理的行(否则会输出所有)(也就是关闭默认的输出) -p选项:打印 [root@centos6 ~]# vim a.txt [root@centos6 ~]# cat a.txt asdf;1324;fdsag 1234567890 qwer asdasdsadasdasdas [root@