Solved

Fixing user files

Posted on 2009-07-13
5
246 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.

730 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