为什么要创建这样的链接:ln -nsf?

And*_*rew 43 linux command-line

这有什么作用?

ln -nsf
Run Code Online (Sandbox Code Playgroud)

我知道ln -s创建一个符号链接,而不是一个硬链接,这意味着您可以删除它并且它不会删除它链接到的想法。但是其他的东西是什么意思?(-nf)

更新:好的...所以我记得你可以从命令行中找到这些东西。这是我从打字中发现的ln --help

-f, --force                 remove existing destination files
-n, --no-dereference        treat destination that is a symlink to a
                            directory as if it were a normal file
Run Code Online (Sandbox Code Playgroud)

但这对我来说仍然不是很清楚这意味着什么。为什么我要创建这样的软/符号链接?

sti*_*mms 44

从 BSD 手册页:

 -f    If the target file already exists, then unlink it so that the link
           may occur.  (The -f option overrides any previous -i options.)

 -n    If the target_file or target_dir is a symbolic link, do not follow
           it.  This is most useful with the -f option, to replace a symlink
           which may point to a directory.
Run Code Online (Sandbox Code Playgroud)


小智 36

-n选项(与 一起-f)强制ln更新指向目录的符号链接。这意味着什么?

假设你有 2 个目录

  • 酒吧

和现有的符号链接

  • 巴兹 -> 酒吧

现在你想更新baz以指向foo。如果你只是这样做

ln -sf foo baz
Run Code Online (Sandbox Code Playgroud)

你会得到

  • baz/foo -> foo
  • baz -> bar(不变),因此
  • 酒吧/富人->富人

如果你添加 -n

ln -sfn foo baz
Run Code Online (Sandbox Code Playgroud)

你得到你想要的。

  • baz -> foo

这就是“无取消引用”的意思:不要解析现有链接并将新链接放在该目录中,而只是更新它。

  • 迄今为止最有帮助的答案。 (4认同)