• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 721
  • Last Modified:

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

?
0
JeffBeall
Asked:
JeffBeall
4 Solutions
 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now