cp命令用于覆盖作为符号链接的目标文件

Die*_*yen 23 linux shell cp

cp命令是否有任何选项可以覆盖作为符号链接的目标文件?

问题如下:

[dthnguyen@dthnguyen test]$ ls -l
total 8
-rw-rw-r--. 1 dthnguyen dthnguyen 5 Feb 21 09:07 a.txt
lrwxrwxrwx. 1 dthnguyen dthnguyen 7 Feb 21 08:55 b.txt -> ./a.txt
-rw-rw-r--. 1 dthnguyen dthnguyen 5 Feb 21 08:55 c.txt
[dthnguyen@dthnguyen test]$ cp c.txt b.txt
Run Code Online (Sandbox Code Playgroud)

复制后,a.txt的内容为c.txt,b.txt仍然链接到a.txt.预期的结果是a.txt保存旧内容,b.txt是一个新的常规文件,其内容与c.txt相同.

Ign*_*ams 34

告诉cp先删除它.

cp --remove-destination c.txt b.txt
Run Code Online (Sandbox Code Playgroud)

  • 有没有办法为目录做这个?我用`-r`试了一下它似乎不起作用. (6认同)
  • 我在OS X 10.9.5上没有看到这个选项. (3认同)