Solved

Fixing user files

Posted on 2009-07-13
5
212 Views
Last Modified: 2012-05-07
Hello,

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.
0
Comment
Question by:Legatie
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24843122
Do you want all files to belong to their home? of just  /home/abcd files? or all files with an owner that does not exist in /etc/passwd
Do you want to do anything with files not under /home?
0
 
LVL 4

Expert Comment

by:djmounce553
ID: 24843211
You can do this using pipes in the following manner.
find / \( -nouser -o -nogroup \) | xargs chown USERNAME
Just specify the user to change it to and you're all set!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24843566
Once you've determined which invalid UiD's belong to which user, you can do

find /home -owner 12345 | xargs chown abcd
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 24847361
try this script

awk -F":" '{ print $3 " " $4 " " $6 }' /etc/passwd | while read uid gid home
do
   find $home -nouser -o -nogroup | xargs chown $uid:$gid
done
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24852217
why B grade? What is missing in the solution / script?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now