Page 1 of 1

How to cp files, including hidden, to an existing directory?

Posted: Sun Jun 11, 2006 5:48 pm
by brakthepoet
Here's one that's been a puzzler for me. At the command line, I would like to recursively copy files and directories to an existing directory, along with any hidden files within those directories. I know that cp can copy files recursively with -R, and preserve their permissions, etc, with -p, but I haven't been able to get the desired results.

The following
cp -Rp /pathtodirectory/old/ /pathtodirectory/new/
gets me what I want, unless /pathtodirectory/new/ already exists. If it exists, I'll end up with /pathtodirectory/new/old/

And this
cp -Rp /pathtodirectory/old/* /pathtodirectory/new/
copies everything except hidden files.

I'm totally stumped at this point. Any pointers in the right direction would be appreciated.

Posted: Sun Jun 11, 2006 6:08 pm
by Karl
Try it with
cp -Rp /pathtodirectory/old/. /pathtodirectory/new/

Posted: Sun Jun 11, 2006 6:28 pm
by brakthepoet
Karl, that's exactly what I was looking for. I knew it had to be something simple but I was just overlooking. Thank you very much for the help.