I've copied a folder of data from one linux server to another via a tarball.

The group ids (GIDs) don't match up on the two servers, so I now have files that look like

-rw-rw-r--   1 tim  1013   88 2008-11-14 10:18 config

There is a mixture of group ownerships in the folder, and I want to keep them owned by different groups on the same server, so I can't just use chgrp -R.

How do I change all files/folders with GID 1013 to another group, without affecting other files/folders?


  • Slightly off topic but... If you are transferring the files via NFS or Samba there are ways to map the ID's between machines, but they must be set up before the transfer begins. – Chris Nava Apr 27 '10 at 14:53
sudo bash -c 'find . -gid 1013 -print0 | xargs -0 chown :1212'

This would change them all files owned by group 1013 to gid 1212. You could add additional options like -type d to find to restrict it to something like only directories, see man find.

  • ta, i always forget about the -0 thing. – Tim Abell Apr 27 '10 at 14:40
find . -gid 1013 | xargs chgrp newgroup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.