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" 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"}' Any help would be appreciated. Thank you. |
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 '-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). |
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. |
Try this, although it may take a long time to execute.
Code:
find /home -type f -user nobody -printf "%h\n" | uniq |
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 |
One final suggestion. "sort -u" (assuming gnu sort) can be used, making uniq unecessary.
|
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 Code:
find /home -user "nobody" | sed 's/^\/home\///' | awk -F"/" '{ print $1 }' | sort | uniq 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"}' Thank you again for everyone's help. |
All times are GMT -5. The time now is 06:43 AM. |