Fixing user files
Posted on 2009-07-13
I am trying to fix files which do not have users. I am using the following find command for it.
find / \( -nouser -o -nogroup \) | xargs ls -ld
Suppose it gives us an output of
-rwxr----- 1 12345 user_unix 943 Jan 13 12:12 /home/abcd/.profile
From the above output it is obvious that this file belongs to user "abcd" but is owned by 12345 which does not exist in /etc/passwd.
Can someone help me with a command or maybe a couple of lines of script to change the file to be owned by user "abcd" from "12345". I have many files like this that needs to be changed.
Thanks in advance.