1

This question already has an answer here:

Why cp --preserve=links doesn't work? I want to copy some symbolic links.From man page:

--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all*

On my CentOS 3.10.0-693.el7.x86_64,it doesn't work.

Following is my steps:

[root@ beau]# ls -l
total 4
lrwxrwxrwx. 1 root root 11 Dec 2 21:49 bar.txt -> foo/bar.txt
drwxr-xr-x. 2 root root 4096 Dec 2 21:41 foo
[root@ beau]# cp --preserve=links bar.txt bar1
[root@ beau]# ls -l
total 4
-rw-r--r--. 1 root root 0 Dec 2 23:08 bar1
lrwxrwxrwx. 1 root root 11 Dec 2 21:49 bar.txt -> foo/bar.txt
drwxr-xr-x. 2 root root 4096 Dec 2 21:41 foo

My questions is :Why the option '--preserve=links' doesn't work?

marked as duplicate by ilkkachu, GAD3R, roaima, Jeff Schaller, sebasth Dec 3 '17 at 15:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Where did that text at the top come from? Was it copied from another question or site? – Jeff Schaller Dec 3 '17 at 14:51
1

In brief: --preserve=links refers to preserving hard links, not symlinks. -P or --no-dereference preserves symbolic links by copying the links themselves, not their targets. -P is standard, in GNU cp it's included in -d, which is included in -a.

Not the answer you're looking for? Browse other questions tagged or ask your own question.