cp command to overwrite the destination file which is a symbolic link
15,539
Tell cp
to remove it first.
cp --remove-destination c.txt b.txt
Author by
Dien Nguyen
Updated on June 07, 2022Comments
-
Dien Nguyen about 2 years
Does cp command have any option to overwrite the destination file which is a symbolic link?
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.