Linux – change the ownership of all the files of a specific user

bashcentoslinuxshellshell-scripting

Is there a way to recursively find all files owned by a user and change them to another user/group in Gnu/Linux?

I assume there must be some magic one liner but my command line wizardry skills are not up to that 🙂

Thanks!

Best Answer

Use the find command with the -user option. Something like:

find / -user john

will eventually turn up all files owned by user "john".

If you want to change their ownership (I would run the find without execution to make sure you have the list you want), then something like:

find / -user john -exec chown harry {} \;

will do it.