如何移动相对符号链接?
我有很多相对符号链接,我想将它们移动到另一个目录。
如何在保留正确路径的同时移动符号链接(具有相对路径的链接)?
I have a lot of relative symbolic links that I want to move to another directory.
How can I move symbolic links (those with a relative path) while preserving the right path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用 readlink -f foo 将相对路径转换为完整路径。所以你会做类似的事情:
编辑:
我注意到你希望保持路径相对。在这种情况下,移动链接后,可以使用 symlinks -c 将绝对路径转换回相对路径。
You can turn relative paths into full paths using
readlink -f foo
. So you would do something like:EDIT:
I noticed that you wish to keep the paths relative. In this case, after you move the link, you can use
symlinks -c
to convert the absolute paths back into relative paths.这是一个保留相对路径的
perl
解决方案:This is a
perl
solution that preserves relative paths:当然使用
ln
:我很惊讶它能起作用,但是
LN(1)
必须足够聪明才能注意到正在发生的事情并帮助您!我什至尝试使用../somethingelse
(这应该是链接重写中的无操作)和..
(这将删除来自链接目标的..
),效果非常好。Use
ln
of course:I was surprised this works, but
LN(1)
must be smart enough to take note of what's going on and help you out! I even tried it with a "newdir" of../somethingelse
(which should be a no-op in the link re-writing) and..
(which will remove a..
from the link target), and it worked wonderfully.改进 Christopher Neylan 的答案:
这也是 https://github.com/tpo/little_shell_scripts 的一部分
Improving on Christopher Neylan's answer:
This is also part of https://github.com/tpo/little_shell_scripts
可以使用
tar
移动包含相关符号链接的文件夹。例如:
One can use
tar
to move a folder containing relative symbolic links.For example: