i have a folder with symlinks:
marek@marek$ ls -al /usr/share/solr/
razem 36
drwxr-xr-x 5 root root 4096 2010-11-30 08:25 .
drwxr-xr-x 358 root root 12288 2010-11-26 12:25 ..
drwxr-xr-x 3 root root 4096 2010-11-24 14:29 admin
lrwxrwxrwx 1 root root 14 2010-11-24 14:29 conf -> /etc/solr/confi want to copy it to ~/solrTest but i want to copy files from symlink as well
when i try to cp -r /usr/share/solr/ ~/solrTest
i will have symlink here:
marek@marek$ ls -al ~/solrTest
razem 36
drwxr-xr-x 5 root root 4096 2010-11-30 08:25 .
drwxr-xr-x 358 root root 12288 2010-11-26 12:25 ..
drwxr-xr-x 3 root root 4096 2010-11-24 14:29 admin
lrwxrwxrwx 1 root root 14 2010-11-24 14:29 conf -> /etc/solr/conf 4 Answers
cp -Lr /usr/share/solr/ ~/solrTestCheck the man page for unix commands with man cp
-L, --dereference always follow symbolic links in SOURCE 2 From man page:
‘-L’ ,‘--dereference’ - Follow symbolic links when copying from them. With this option, cp cannot create a symbolic link. For example, a symlink (to regular file) in the source tree will be copied to a regular file in the destination tree.
So this is the option you should try.
cp -r -L /usr/share/solr/ ~/solrTestFrom the cp(1) man page:
-L, --dereference always follow symbolic links in SOURCE
One quick solution is to:
$ mkdir dest_dir
$ cp symlink_dir/* dest_dir/the drawback is that you have to create the destination directory first
1