I want to delete a group using groupdel command, but before doing this I want to assign all files belonging to this group to another one is there a way to do this?

I know that I can use find / -gid group_id to find files that belong to this groups and then manually assign them to new one. I seek a way to automatically do the task.


find / -group <groupname> -exec chown :<groupname> {} \+

should do the trick. Just replace <groupname> with the appropriate name.

find allows you to call arbitrary commands on the files it returns, using the -exec primary. In this case, as we know we want to change the group ownership of each matching file, we can simply pass the chown command (and any arguments - in this case, the group name to whose ownership we wish to transfer matching file names, preceded by :, which tells chown to treat it as a group name and not as a user name) as the argument to -exec. The file name returned by find is inserted into the command in place of the {}, and +; tells find that it has reached the end of the external command, and should parse any additional parameters as its own. Using \+ rather than \; tells find to process multiple files in each command (so it's more efficient).

  • 2
    Please explain it a bit more. – Sam May 15 '12 at 16:11
  • Edited my answer. Does that clear it up a bit? – D_Bye May 15 '12 at 16:29

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.