Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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).

share|improve this answer
Please explain it a bit more. – XinHua 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 posting your answer, you agree to the privacy policy and terms of service.

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