I want to see top 5 users,who have occupied most amount of disk space in a filesystem.
But not sure how to do it.
I can get the usage for a particular user
find . -user user -type f exec df -h {} \;|awk '{ s = s+$1 } END { print "Total used: ",s }'
But how to get without specifying any user for a filesystem ?
ls -ls (on my linux and FreeBSD systems) shows the files' and directories' allocated 1k-blocks in the first column. All the script does is sum these up per user. Test it on small directories to verify it's true/correct.
Thank u so much for ur advise.
I tried these two commands below :
find /home -exec ls -ls {} + | awk '{sum[$4]+=$1} END {for (u in sum) print u, sum}'
0
ra60 385344
ls -ls |awk '{s=s+$1} END { print "Total used: ",s }'
Total used: 192392
As per my understanding these two should return the same amount of space used because I tried this in my home directory and there are files owned only by me.
So - run the two command along with each other without piping through awk and compare line by line. Are you the only user in the /home directory?
Try to list directories only:
find /home -type d -exec ls -ls {} + | awk '{sum[$4]+=$1} END {for (u in sum) print u, sum}'