Conditionally change group ID
I have a set of files that have a group ID number where no group exists in the system with that number.
I want to recursively read the group IDs of all (including hidden) files in the current and sub-dirs, test each file's group ID, and if it equals the search GID number, I want to execute a chgrp command on that file. Anyone have an admin script already made for this task? Thanks in advance! |
'cd' to the directory that you want to start in.
Then try Code:
find . -group xxxx -exec ls -l {} \; If you're happy with the list Code:
find . group xxxx -exec chgrp yyyy {} \; Or, if you want to confirm each one Code:
find . group xxxx -ok chgrp yyyy {} \; |
Thanks, Tommy! I'll give that a try and post back here.
|
When I've had the problem, I've just created a group with the "unassigned" number, and proceeded from there. But the find solution should suggested by johnE1 will also work.
|
SOLVED: Conditionally change group ID
Tommy, your examples were very helpful. Thank you!
Here's what I ended up using. To verify find results: find . group xxxx -print0 | xargs -0 ls -AL To change group of each file (and sub-directory) found: find . group xxxx -print0 | xargs -0 chgrp yyyy NOTE: Those are zeroes (0's). |
Cool. Your way is an excellent alternative, especially (I think) when there are a very large number of files to change.
As the Perl people say, "Tim Toady" - There's More Than One Way To Do It (TMTOWTDI). |
All times are GMT -5. The time now is 06:52 PM. |