2012-02-21 93 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