0

I have 3 specific user accounts (less than 10 anyway), for all files & folders under a specific /data or /home directory, I want to change just the group ownership of all occurring files/folders of those specific users.

I don't know where everywhere might be (besides /home and /data) so I want to do a <what?> -R on /. Is there a way to do that? The existing group is named XYZ and I want to change all files & folders that are owned by ron.XYZ to ron.users. How can that be done?

ron
  • 5,749
  • 7
  • 48
  • 84

1 Answers1

2

Use find to identify the target files, and then apply the change of group to those.

find / -user ron -group XYZ -print -exec chgrp users {} +

You can omit the -print if you aren't worried about seeing which files are being changed. You can also (temporarily) omit the -exec … + if you first want to see which files would be affected before changing them.

You can extend the match to all three user accounts at once:

find / \( -user ron -o -user alice -o -user bob \) -group XYZ -print -exec chgrp users {} +

Note that you will descend into /proc (and other pseudo filesystems). You can safely ignore errors about changing ownerships there. You can use -prune to omit such filesystems:

find / \( -path /proc -o -path /dev -o -path /sys \) -prune -o …as above…
roaima
  • 107,089
  • 14
  • 139
  • 261
  • 1
    thanks, this worked well; I just used your first example and let it squawk for 3 seconds about `/proc` – ron Nov 02 '22 at 20:41