无法覆盖符号链接 RedHat Linux
我创建了一个符号链接:
sudo ln -s /some/dir new_dir
现在我想覆盖符号链接以指向新位置,但它不会覆盖。我已经尝试过:
sudo ln -f -s /other/dir new_dir
我总是可以sudo rm new_dir
,但如果可能的话,我宁愿让它相应地覆盖。有什么想法吗?
I have created a symbolic link:
sudo ln -s /some/dir new_dir
Now I want to overwrite the symbolic link to point to a new location and it will not overwrite. I have tried:
sudo ln -f -s /other/dir new_dir
I can always sudo rm new_dir
, but I would rather have it overwrite accordingly if possible. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我有用。
-n
不会取消引用目标符号链接。works for me. The
-n
doesn't dereference the destination symlink.您可以创建它然后移动它:
编辑:缺少-Tf,将目录视为常规文件并且不提示覆盖。
这样你就会覆盖它。
You can create it and then move it:
edit: Missing -Tf, to treat the directory as a regular file and don't prompt for overwrite.
This way you will overwrite it.
由于 mikeytown2s 评论中的链接已损坏,我将解释为什么 redent84s 答案 更好:
虽然
可以完成工作,它不是一个原子操作,正如您使用 strace 所看到的:
当您有一个指向该符号链接的网络服务器根时,这一点很重要。当符号链接被删除并再次创建时,即使在一微秒的时间内,它也可能会导致错误。
为了防止错误,请改用:
这将创建一个临时链接,然后在原子操作中覆盖currentDir。
Since the Link from mikeytown2s comment is broken, i will explain why redent84s answer is better:
While
does the job, it is not an atomic operation, as you can see with strace:
This is important when you have a webserver root pointing to that symlink. It could cause errors while the symlink is deleted and created again - even in the timespan of a microsecond.
To prevent errors use instead:
This will create a temporary Link and after that overwrite currentDir in an atomic operation.