Linux cp 命令覆盖作为符号链接的目标文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9371222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cp command to overwrite the destination file which is a symbolic link
提问by Dien Nguyen
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 具有相同的内容。
采纳答案by Ignacio Vazquez-Abrams
Tell cp
to remove it first.
告诉你cp
先删除它。
cp --remove-destination c.txt b.txt