Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

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
2  
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

 
discard

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.