LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 08: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, 08:41 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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 08:43 AM.
 
1 members found this post helpful.
Old 03-10-2012, 09: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 09:02 AM.
 
Old 03-10-2012, 09:23 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
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, 11:00 AM   #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 01:25 PM.
 
Old 03-11-2012, 12:36 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
One final suggestion. "sort -u" (assuming gnu sort) can be used, making uniq unecessary.
 
1 members found this post helpful.
Old 03-12-2012, 02: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



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 07:01 PM
calculating the memory usage by each user in all the network attached systems krishnalite Programming 0 07-20-2010 12:54 AM
Managing user data etamayo Linux - Software 3 01-12-2006 07:02 PM
Managing user permissions bountyhunter General 2 10-17-2005 01:38 PM
Managing user rights - how? Sastian Linux - Newbie 2 09-26-2003 12:33 PM

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

All times are GMT -5. The time now is 03:05 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
Open Source Consulting | Domain Registration