7

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.

user2015453
  • 4,234
  • 5
  • 22
  • 25

2 Answers2

9

From man cp:

   -L, --dereference
          always follow symbolic links in SOURCE
that other guy
  • 101,688
  • 11
  • 135
  • 166
6

Use -L option like this:

cp -RL ~/foo ~/bar
anubhava
  • 664,788
  • 59
  • 469
  • 547