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

时间:2022-05-01 16:25:38

Does cp command have any option to overwrite the destination file which is a symbolic link?

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

The problem is as follows:

问题如下:

[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

After do the copy, a.txt has the content of c.txt, b.txt still links to a.txt. The expected result is a.txt holds the old content, b.txt is a new regular file that has the same content as c.txt.

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

1 个解决方案

#1


26  

Tell cp to remove it first.

告诉cp先删除它。

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

#1


26  

Tell cp to remove it first.

告诉cp先删除它。

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