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

Hey drop us a line about the show. Feel free to ask questions, provide feedback and criticism, or just ramble on about anything your little heart desires.

Moderators: snarkout, Patrick, dann

Post Reply
brakthepoet
Posts: 39
Joined: Wed Sep 14, 2005 2:48 pm

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

Post by brakthepoet » Sun Jun 11, 2006 5:48 pm

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.

Karl
Posts: 47
Joined: Fri Jul 08, 2005 11:42 am
Location: NJ

Post by Karl » Sun Jun 11, 2006 6:08 pm

Try it with
cp -Rp /pathtodirectory/old/. /pathtodirectory/new/

brakthepoet
Posts: 39
Joined: Wed Sep 14, 2005 2:48 pm

Post by brakthepoet » Sun Jun 11, 2006 6:28 pm

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.

Post Reply