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'

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Robbo_UK
  • 11,351
  • 25
  • 81
  • 117

1 Answers1

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
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • 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 06:57
  • 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 logic – Sedat Kilinc Aug 23 '18 at 11:43