为什么ln -sf不会覆盖目录的现有链接 [英] Why ln -sf does not overwrite existing link to directory

查看:165
本文介绍了为什么ln -sf不会覆盖目录的现有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档,命令 ln -f 删除现有的目标文件.这是否意味着如果我创建符号链接,-f应该删除覆盖目标位置上任何现有符号链接的内容吗?

According to documentation, command ln -f removes existing destination file. Does this mean that if I create a symlink, -f should remove of overwrite any existing symlink at destination?

我有一个符号链接,例如L,指向DIR1,然后键入 ln -sf DIR2 L .但是L仍然指向DIR1.仅在 rm L 之后,此命令才会创建指向DIR2的链接.

I have a symlink, say, L, pointing to DIR1 and type ln -sf DIR2 L. But L still points to DIR1. Only after rm L this command creates a link pointing to DIR2.

通过符号链接到文件,它的行为符合预期.

With symlinks to files it behaves as expected.

指向目录的链接有什么问题?(在Ubuntu 16.04.2 LTS和Windows WSL上为bash 4.3.48)

What's wrong with links to directories? (bash 4.3.48 on Ubuntu 16.04.2 LTS and Windows WSL)

推荐答案

运行时:

ln -sf DIR2 L

这将在DIR1内创建一个符号链接,导致L指向DIR1,而ln取消引用它,从而创建 L/DIR2->.DIR1 .

This is creating a symlink inside DIR1 cause L points to DIR1 and ln dereferences it, creating L/DIR2 -> DIR1.

以下内容:

rm -fr DIR1 DIR2 L
mkdir DIR1 DIR2
ln -v -s DIR1 L
ls -la L
ln -v -f -s DIR2 L
ls -la L

将输出:

'L' -> 'DIR1'
lrwxrwxrwx 1 runner runner 4 Oct 21 18:13 L -> DIR1
'L/DIR2' -> 'DIR2'
lrwxrwxrwx 1 runner runner 4 Oct 21 18:13 L -> DIR1

要处理此问题,请使用 =-no-dereference 选项,如

To handle that, use the --no-dereference option as indicated in answer in this thread on superuser.com.

这篇关于为什么ln -sf不会覆盖目录的现有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆