Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linux copy symbolic link [closed]

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'

like image 859
Robbo_UK Avatar asked Apr 26 '12 09:04

Robbo_UK


People also ask

Can you copy a symbolic link?

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.

How do I copy a directory symbolic link in Linux?

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.

Does rm remove symlinks?

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.


1 Answers

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 
like image 55
dogbane Avatar answered Oct 02 '22 11:10

dogbane