Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a deep and complex file system where some files have been accidently written by root. I want to change the ownership of those files back to the original owner in one go.

I am playing with commands like:

find /folder -type f | xargs ls -l | grep "root root" 

but there is a lot of garbage coming out too.

I want to make a list first and then change only the files in that list after confirmation.

share|improve this question
find /folder -type -f -uid 0 

will find all files under the directory owned by root, -user root would also work, naturally.

If all files below /folder should be owned by the same user/group, you could simply do an recursive chown:

chown -R user:group /folder
share|improve this answer


find /folder -uid 0 >/tmp/root.files

to get a list of files owned by root. Once you have reviewed the list you could use

while read file 
    chown user:group "$file"

done </tmp/root.files
share|improve this answer

As in the other answers use find with either -uid 0 or -user root to find files belonging to root. Then use the -execaction:

find /folder -type f -uid 0 -exec chown root:root {} \;

share|improve this answer

Your Answer


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.