unix cp command

i want to cp files from one drive to another on the same server, but i would like to retain the owner, group, and user permissions. also, all the files i want to copy start with the user's name, so is there a way to use grep or something like it to cp just the files that start with this user's name? would it be something like

cp /backup/directory/username* /livedirectory/directory

?
LVL 1
JeffBeallAsked:
Who is Participating?
 
woolmilkporcCommented:
Yes, but use "cp -p ..." to preserve ownership and permissions. Additionally consider using the "-r" flag to recurse into subdirs, if desired.

wmp
0
 
fosiul01Commented:
Try cp -p

p preserve the owner ship.

0
 
rubeneCommented:
Hi there,

Use the -p switch of the cp command to retain the owner/group and other file attributes.

So use cp -R -p /backup/directory/* /livedirectory/directory

Not sure if your username* solution works to recursively copy all files starting with the username. If it doesn't work you could try using find and using its output as input for the cp command. You'd get something like this:

find /backup/directory -type f -name "username*" -exec cp -p {} /livedirectory/directory;

I didn't test this, so use at your own risk. ;)

Hope this helps.
Ruben.
0
 
point_pleasantCommented:
could try

find . /backup/directory/username* | cpio -pdumv --owner username:group /livedirectory/directory


0
 
JeffBeallAuthor Commented:
thank you for the help, the cp -r worked great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.