[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Fixing user files

Posted on 2009-07-13
5
Medium Priority
?
268 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
[X]
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
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 1500 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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…
Suggested Courses

656 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