2012-02-21 96 views
15

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

的问题如下:

[[email protected] 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 
[[email protected] test]$ cp c.txt b.txt 

做副本后,A.TXT有c.txt的内容,b.txt仍链接到a.txt中。预期的结果是a.txt包含旧内容,b.txt是与c.txt具有相同内容的新常规文件。

回答

24

告诉cp先删除它。

cp --remove-destination c.txt b.txt 
+0

它的工作原理!非常感谢Ignacio Vazquez-Abrams – 2012-02-21 02:37:53

+4

有没有办法做到这一点的目录?我用'-r'试过了,它似乎没有工作。 – Ajedi32 2013-06-17 18:38:27

+3

我在OS X 10.9.5上看不到这个选项。 – bolinfest 2014-10-31 06:26:42