Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/conf

i 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
share|improve this question

migrated from stackoverflow.com Nov 30 '10 at 21:56

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers 4

cp -Lr /usr/share/solr/ ~/solrTest

Check the man page for unix commands with man cp

   -L, --dereference
          always follow symbolic links in SOURCE
share|improve this answer
    
I get "cp: the -H, -L, and -P options may not be specified with the -r option." –  balupton Apr 22 '12 at 13:45
1  
@balupton: try -LR –  pt2ph8 May 30 '13 at 22:12
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment
cp -r -L /usr/share/solr/ ~/solrTest

From the cp(1) man page:

  -L, --dereference
        always follow symbolic links in SOURCE
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.