I am trying to write a script that fixes the ownership of all files owned by a specific user, after changing the user's UID.
Currently, I run:
chown -Rhc --from=${OLD_UID} ${NEW_UID} / chown -Rhc --from=:${OLD_UID} :${NEW_UID} / Where OLD_UID and NEW_UID are the old and new UIDs of the user I have just modified.
This has the desired effect, but always exits with a return code of 1, because of errors like this:
chown: cannot access ‘/proc/1103/task/1103/fd/4’: No such file or directory chown: cannot access ‘/proc/1103/task/1103/fdinfo/4’: No such file or directory chown: cannot access ‘/proc/1103/fd/4’: No such file or directory chown: cannot access ‘/proc/1103/fdinfo/4’: No such file or directory My theory is that the process finding all files picks up its own process, which then does not exist when chown tries to access it.
I could just throw away the return code from the commands, but I would prefer not to in case I end up ignoring real errors.
Can anyone suggest an alternative approach that will not report false errors?