The /bin folder of Ubuntu 14.04 has files with dependencies. I want to copy the symbolic links along with the files, into a separate directory. Is there an inbuilt command for this?

  • What do you mean by "dependencies"? It could mean "the libraries that each command is using". – Kusalananda Apr 11 at 12:21
  • Yes, I meant libraries. – priyalsoni Apr 12 at 5:19

Use cp -P (capital P) to move 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. cp -R might do one or the other depending on the unix variants; GNU cp (as found on CentOS) defaults to -P.

Even with -P, you can copy the target of a symbolic link to a directory on the command line by adding a / at the end: cp -RP foo/ bar copies the directory tree that foo points to.

GNU cp has a convenient -a option that combines -R, -P, -p and a little more. It makes an exact copy of the source (as far as possible), preserving the directory hierarchy, symbolic links, permissions, modification times and other metadata. shareeditflag

  • Using these commands, cp -RP and cp -a, breaks the links and the files cannot be accessed after that. – priyalsoni Apr 12 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.