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

时间:2012-02-21 02:15:51

标签: 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

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

1 个答案:

答案 0 :(得分:33)

告诉cp先删除它。

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