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'
A symbolic link encountered in the tree traversal is copied instead of the file pointed to by the symbolic link. If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. This option causes cp to create special files rather than copying them as normal files.
Use cp -P (capital P) to never traverse any symbolic link and copy the symbolic link instead. This can be combined with other options such as -R to copy a directory hierarchy — cp -RL traverses all symbolic links to directories, cp -RP copies all symbolic links as such.
The rm command is the dedicated tool for deleting files and directories from the system. Because the symlink itself is a file, we can use the rm command to remove it. The following rm command will remove the symlink. To remove multiple symlinks, use rm as you would to remove multiple files.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With