linux copy symbolic link

linux copy symbolic link [closed]

up vote 19 down vote favorite

1

How do I copy a symbolic link from one directory to another?

ls -ls

file1.txt
file2.txt
files -> /mnt/iscsi-nfs-share/faulttracker-files

what I'm looking to do is copy files symbolic link into another directory?

cp files /var/copylinktohere/

the above results in cp: omitting directory `files'

linux shell command-line symlink cp

shareimprove this question

edited Dec 30 '13 at 0:44

Benjamin

10.9k1692169

asked Apr 26 '12 at 9:47

Robbo_UK

93562649

closed as off-topic by Benjamin, bmargulies, iandotkelly, Tim Dean, Michael Kohne Dec 30 '13 at 2:59

  • This question does not appear to be about programming within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.
 
    

im only looking to copy the symlink not the actual contents of the directory – Robbo_UK Apr 26 '12 at 9:48

5  

Did you have a look in the manual pages? If not, is --no-dereference what you're looking for? – HonkyTonk Apr 26 '12 at 9:52

    

thanks for this gave plus one. I found all the options available a little confusing. – Robbo_UK Apr 26 '12 at 9:59

3  

Belongs to unix.stackexchange.com – Benjamin Dec 30 '13 at 0:43

    

@Benjamin: Fair comment — no mention of C. It is still on topic as it is about how to write shell programs (even if it is a one-liner). As such, it is fine on Stack Overflow. – Jonathan Leffler Dec 30 '13 at 14:11

add a comment

1 Answer

active oldest votes

up vote 33 down vote accepted

Use the -d option:

cp -d files /var/copylinktohere/

From man cp:

 -d     same as --no-dereference --preserve=link --no-dereference
          never follow symbolic links

shareimprove this answer

answered Apr 26 '12 at 9:51

dogbane

132k40230317

 
    

does this work if the symbolic links are not relative? ie copying into a destination directory higher or lower than the source directory. – Andrew Brown Mar 20 '14 at 6:57

add a comment

Not the answer you're looking for? Browse other questions tagged linux shell command-line symlink cp or ask your own question.

你可能感兴趣的:(Linux相关)