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,844
  • 5
  • 25
  • 27

2 Answers2

10

From man cp:

   -L, --dereference
          always follow symbolic links in SOURCE
that other guy
  • 116,971
  • 11
  • 170
  • 194
7

Use -L option like this:

cp -RL ~/foo ~/bar
anubhava
  • 761,203
  • 64
  • 569
  • 643