linux copy symbolic link [closed]
Asked Answered
K

1

32

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'

Kolk answered 26/4, 2012 at 9:47 Comment(5)
im only looking to copy the symlink not the actual contents of the directoryKolk
Did you have a look in the manual pages? If not, is --no-dereference what you're looking for?Toronto
thanks for this gave plus one. I found all the options available a little confusing.Kolk
Belongs to unix.stackexchange.comGaelan
@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.Skinnydip
M
52

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
Manzoni answered 26/4, 2012 at 9:51 Comment(2)
does this work if the symbolic links are not relative? ie copying into a destination directory higher or lower than the source directory.Starofbethlehem
wouldn't it be quite the other way around? Absolute symlinks work from every path, while relative symlinks can't work, if you change their path. It's quite logicRainger

© 2022 - 2024 — McMap. All rights reserved.