Space usage by top 5 users in a filesystem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Space usage by top 5 users in a filesystem
# 1  
Old 12-19-2014
Lightbulb Space usage by top 5 users in a filesystem

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
Code:
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 ?

Then I can sort for top 5 usages.

Please advise..Thanks in advance !!

Last edited by vbe; 12-19-2014 at 05:38 AM.. Reason: code tags next time, thanks...
# 2  
Old 12-19-2014
Try
Code:
find /home -exec ls -ls {} + | awk '{sum[$4]+=$1} END {for (u in sum) print u, sum[u]}'
 0
user1 2753844
sys 2888
root 16872

For disk usage you'll need to sum up the disk blocks allocated, not the actual file sizes, so we need to run ls -ls.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-19-2014
could you plz explain how this works because I am not sure whether the space it's showing is correct or not..
# 4  
Old 12-19-2014
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.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-19-2014
Thank u so much for ur advise.
I tried these two commands below :
Code:
find /home -exec ls -ls {} + | awk '{sum[$4]+=$1} END {for (u in sum) print u, sum[u]}'
 0
ra60 385344

Code:
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.

But, these are different.

Last edited by Franklin52; 12-19-2014 at 07:07 AM.. Reason: Please use code tags
# 6  
Old 12-19-2014
There are alternatives not using awk.
If the du command is your cup-o-tea, you could run something like this as root user.
Code:
$ for u in $(ls /home/); do printf "%s\n" "$(du -sh /home/$u)"; done | sort >> outfile && head -n 5 outfile
------------
256M    /home/brutus/
176M    /home/userA/
126M    /home/izzy/
36M     /home/linus/
31M     /home/maud/


Last edited by ongoto; 12-19-2014 at 07:51 AM..
# 7  
Old 12-19-2014
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:
Code:
find /home -type d -exec ls -ls {} + | awk '{sum[$4]+=$1} END {for (u in sum) print u, sum[u]}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Showing all users in 'users' and 'top' commands

Hi All, I work in a multi user environment where my school uses Red Hat Linux server. When I issue commands such as "top" or "users", I get to see what others are doing and what kinds of applications they are running (even ps -aux will give such information). "users" will let me know who else is... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

2. Shell Programming and Scripting

Filesystem usage with more than 80%.

Hi All, I need to display the output of rah "df -m" only for the filesysytems those are touching or crossing 80%. Im using SuSE Linux box and the output of original rah command is- /dev/NODE0001 557900 446681 83319 75% /db2fs/NODE0001 /dev/NODE0002 ... (5 Replies)
Discussion started by: NARESH1302
5 Replies

3. Shell Programming and Scripting

Filesystem Usage Script

Hey guys I am learning Linux and I am working on script for a college class project to check usage of file system. I pulled this from a different site but have to tweak it a little to work but I still get errors. Here is what I got so far. ALERT=5 function main_prog() { while read output;... (1 Reply)
Discussion started by: jcsx6245
1 Replies

4. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

5. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

6. Solaris

Filesystem Usage

Hi Guys... I want to change the below script to send an alert when my file system is greater than 5G. # If any filesystem has less than 5k, issue an alert if Regards (3 Replies)
Discussion started by: Phuti
3 Replies

7. Shell Programming and Scripting

Script to check top 5 biggest disk space users

Hi all, I am needing a bash shell script to generate a list of the top 5 users using the most disk space. I am thinking that the du command would be used somehow but I am at a loss. Can anyone help? Thanks! (3 Replies)
Discussion started by: sytemx
3 Replies

8. Programming

how to get filesystem usage in c

hi, everyone Can anybody tell me how to get free blocks and total blocks of filesystem in c. I am working on a hp-unix Thanks in advance. (8 Replies)
Discussion started by: mika
8 Replies

9. AIX

How to find the top 6 users (which consume most space)?

Hi everybody, I want to know if there is any posibility to find out - on an AIX system - which are the the users who consume most space or at least a posibility to obtain a list with all the users and how much space are they consuming ? Trying to use du command was useless. Any idea?... (5 Replies)
Discussion started by: RebelDac
5 Replies

10. UNIX for Dummies Questions & Answers

How to get system memory usage like top

Hello all im working on sunos machine that dont have the top installed and can't be install , now i need to get information similar to what top gives me about the cpu usage and so can it be done somehow else where ? (3 Replies)
Discussion started by: umen
3 Replies
Login or Register to Ask a Question