Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Fixing user files

Posted on 2009-07-13
5
238 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

856 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