Copying a soft link usually copies the file the soft link refers to and does not replicate the soft link.
If you wish to use cp
to copy soft links as new soft links, specify the -a option to cp
.
cp -a libAbc.so* /path/to/another/folder
The info page for cp
says:
`-a'
`--archive'
Preserve as much as possible of the structure and attributes of the
original files in the copy (but do not attempt to preserve internal
directory structure; i.e., `ls -U' may list the entries in a copied
directory in a different order). Equivalent to `-dpR'.
The key is to select the "archive" option of the command used to copy the link. rsync
is an effective alternative as Maxim Egorushkin points out, and rsync
has the capability of copying extended attributes and ACLs if the command includes the appropriate command-line arguments.
rsync -aAX libAbc.so* /path/to/another/folder
The rsync
man page says:
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
-A, --acls preserve ACLs (implies -p)
-X, --xattrs preserve extended attributes
In the OP's use case, the -A and -X are not needed.
A caveat is that if the soft link is a relative link, copying it to a new location may make the link inoperative because it does not point to an absolute path.
For example:
$ ls -al /usr/lib/rpmpopt
lrwxrwxrwx 1 root root 19 2012-05-02 12:40 /usr/lib/rpmpopt -> rpm/rpmpopt-4.4.2.3
cp -a /usr/lib/rpmpopt ${HOME}/tmp
and rsync -av /usr/lib/rpmpopt ${HOME}/tmp
on my machine both create a broken link rpmpopt -> rpm/rpmpopt-4.4.2.3
because my local copy has no rpm sub-folder. One needs to consider this fact when deciding what to copy.
This link is broken because ${HOME}/tmp/rpm is not present:
$ ls -nl ${HOME}/tmp/rpmpopt
lrwxrwxrwx 1 505 700 19 2016-05-24 10:04 /home/kbulgrien/tmp/rpmpopt -> rpm/rpmpopt-4.4.2.3