Copying symbolic links (Unix/Linux)

At some point, you might come across a situation where you have some files and a bunch of symlinks (symbolic links) in a folder and you wish to copy the data that is pointed at by the symlinks and not just blank links. If you are using Redhat Enterprise Linux, this should automatically happen when you call the cp command. However, on UNIX platforms or Linux distributions, this is not the case by default. In those cases, you will have to issue the following command:

cp -L {file(s)} {destination folder}

The -L option in cp command forces it to follow (dereference) symlinks and copy the data that is pointed at by the symlink.

In case you do not want to follow symlinks, you can issue the following command instead:

cp -P {file(s)} {destination folder} 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.