LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-10-2012, 09:07 AM   #1
alankru
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Rep: Reputation: Disabled
Help with managing/calculating user files


Hi,

I am using CentOS to run a web server, but I believe that this is a simple newbie question so I hope that I am posting this in the correct forum.

I have a number of users with files owned by the user "nobody" in their home directories. Would someone be able to help me with the following please?

1. How would I go about finding the user's that have files in their home directories that are owned by "nobody"? I know that I can do

Code:
#find /home -user "nobody"
however, I would like to have a summary of the locations where these files are, rather than a verbose listing of every file. Is this possible?

2. A long time ago, I was given a command to scan a user's home directory and calculate the disk usage of their "nobody" files:

Code:
#find /home/directory -user nobody | xargs -i du -b "{}" | awk '{sum+=$1} END {print sum/1024/1024" MB"}'
However, when I run this command on an example user, it doesn't show the true disk usage of the files owned by the "nobody" user. Furthermore, if I use the same command to find files owned by the example user, it comes back with 6GB, which is not correct either as they have a quota of 800MB. So clearly something isn't right with that command.

Any help would be appreciated. Thank you.
 
Old 03-10-2012, 09:41 AM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,658

Rep: Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539
My suggestion for an amended command.
Code:
find /home/directory -type f -user  nobody -print0  | xargs -0 du -b | awk '{sum+=$1} END {print sum/1024/1024" MB"}'
The '-type f' option to find will only find regular files.
The '-print0' option to find together with the '-0' option to xargs will handle filenames with spaces.
The now deprecated '-i' option to xargs is superfluous (and wrongly had no replacement string specified in your original).

Last edited by allend; 03-10-2012 at 09:43 AM.
 
1 members found this post helpful.
Old 03-10-2012, 10:00 AM   #3
alankru
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thumbs up

That works perfectly, thank you so much for your help!

Do you know what I can do about finding a listing of the directories where the "nobody" owned files are (across the entire /home drive)? Is this possible please?

EG. I run a command that gives me a listing like:

/home/user/folder/
/home/user/folder2/
/home/user/folder2/folder3

etc.

Last edited by alankru; 03-10-2012 at 10:02 AM.
 
Old 03-10-2012, 10:23 AM   #4
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,658

Rep: Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539Reputation: 1539
Try this, although it may take a long time to execute.
Code:
find /home -type f -user nobody -printf "%h\n" | uniq
 
1 members found this post helpful.
Old 03-10-2012, 12:00 PM   #5
alankru
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thanks very much again allend, you have helped me out tremendously!

What I have now done is also pipe it to sort and redirect it to a file so that I can go through it:

Code:
find /home -type f -user nobody -printf "%h\n" | sort | uniq > nobodyfiles.txt
Thanks again!

Last edited by alankru; 03-10-2012 at 02:25 PM.
 
Old 03-11-2012, 01:36 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
One final suggestion. "sort -u" (assuming gnu sort) can be used, making uniq unecessary.
 
1 members found this post helpful.
Old 03-12-2012, 03:58 PM   #7
alankru
LQ Newbie
 
Registered: Mar 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Great, thanks for that improvement on mine.

What I needed for my purposes was to also get a list of the user's who had "nobody" files in their home directories. I was able to take the data from the earlier
Code:
find /home -type f -user nobody -printf "%h\n" | sort | uniq > nobodyfiles.txt
command and I then put it into a spreadsheet application to get a list of users. However, for anyone else looking at this thread, someone else suggested to me that the following command could be used (I didn't try it myself due to the amount of time it takes to execute):

Code:
find /home -user "nobody" | sed 's/^\/home\///' | awk -F"/" '{ print $1 }' | sort | uniq
This will list all users that have at least one file owned by nobody. Of course, the uniq command can be removed as per your post David the H.

One thing that I came across with the command
Code:
find /home/directory -type f -user  nobody -print0  | xargs -0 du -b | awk '{sum+=$1} END {print sum/1024/1024" MB"}'
was that if a user does not have any files in their home directory owned by the nobody user, then a value of "100.58 MB" gets returned. This is something to watch out for, but it didn't cause me a problem as I worked through each user manually from the user listing I got earlier. Therefore, I knew that the figures could be relied upon as there genuinely were nobody files in the user's home directory.

Thank you again for everyone's help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: New Linux User's Guide To Managing Your Files LXer Syndicated Linux News 0 11-26-2010 08:01 PM
calculating the memory usage by each user in all the network attached systems krishnalite Programming 0 07-20-2010 01:54 AM
Managing user data etamayo Linux - Software 3 01-12-2006 08:02 PM
Managing user permissions bountyhunter General 2 10-17-2005 02:38 PM
Managing user rights - how? Sastian Linux - Newbie 2 09-26-2003 01:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration