We help IT Professionals succeed at work.

Stupid Linux CP question

erzoolander
erzoolander asked
on
I have two directories.

/var/www/whatever/docs

and
/var/www/second/docs

I want to copy, recursively, preserving the permissions, the files from the first "docs" directory to the second "docs" directory.  Not replace the directory, but just copy the contents.

What's the syntax for that?

When I go...

cp -r -p /var/www/whatever/docs/ /var/www/second/docs/ - I get a "docs/docs/" directory.

What's the right way of doing it?  (I assume the -r -p flags are correct also, right?)

Thanks!
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Use ..../docs/*  as the source
Top Expert 2011
Commented:
cp -Rp /var/www/whatever/docs/* /var/www/second/docs/

Open in new window

CERTIFIED EXPERT

Commented:
This is by far my favorite way to "merge" the two folders, which is what I think you're after:
(cd /var/www/whatever/docs && tar cpf - . ) | (cd /var/www/second/docs && tar xvfp -)

Open in new window

Author

Commented:
Thank you!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.