Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change ownership of file during copy

Tags:

unix

copy

How to change the ownership of a file during copy itself. I mean in cp command how to add ownership

I cant rely on --preserve and copying the file and then changing the ownership of file due to some constraints. Thanks

like image 415
user1215553 Avatar asked Aug 01 '13 12:08

user1215553


1 Answers

As stated here: https://unix.stackexchange.com/questions/124855/move-files-and-change-ownership-at-the-sametime

Use rsync(1):

rsync \
  --remove-source-files \
  --chown=wanteduser:wantedgroup \
    /home/oldfolder /home/newfolder
like image 50
Morlock Avatar answered Oct 22 '22 21:10

Morlock