强制cp复制悬空符号链接
有没有办法强制cp
(Bash 4.2.5,Ubuntu 12.04)复制到悬空的符号链接?
cp a-file path/to/danling/symlink/a-file cp: not writing through dangling symlink `path/to/danling/symlink/a-file`
在这种情况下, cp -f
似乎无能为力,导致相同的消息。
在复制之前使cp
删除目标文件:
$ ln -s /random/file f $ cp -faf cp: not writing through dangling symlink 'f' $ cp --remove-destination af $ diff af && echo yes yes
来自man cp
:
--remove-destination remove each existing destination file before attempting to open it (contrast with --force)
只需使用unlink theSymLink
,其中theSymLink
是实际的符号链接,然后再试一次