Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying (cp) a thing that a symlink points to rather than the symlink itself [closed]

Tags:

bash

unix

I know that the dirs ~/foo and ~/bar already exist.

I know that "cp -R ~/foo ~/bar" will recursively copy the ~/foo directory into the ~/bar directory, potentially causing ~/bar/foo to be created.

But what if foo is a symlink to a directory? Can I make the cp command copy the directory that the symlink points to, instead of the symlink itself?

Because with the above command, if foo is a symlink, then ~/bar/foo will actually be just a symlink.

like image 919
user2015453 Avatar asked Feb 05 '13 21:02

user2015453


2 Answers

From man cp:

   -L, --dereference
          always follow symbolic links in SOURCE
like image 129
that other guy Avatar answered Dec 31 '22 03:12

that other guy


Use -L option like this:

cp -RL ~/foo ~/bar
like image 22
anubhava Avatar answered Dec 31 '22 02:12

anubhava