Operating System - HP-UX
1836729 Members
2800 Online
110109 Solutions
New Discussion

Re: top 3 users in a directory

 
Rosli Ahmad
Frequent Advisor

top 3 users in a directory

Hi,
I wonder if there's a quick way to list top 3 users consuming the most diskspaces in a certain directory.

Thanks.
6 REPLIES 6
MarkSyder
Honored Contributor

Re: top 3 users in a directory

Do these users have their own sub-directories within the directory? If so, then du -k will help you:

du -k|sort -k1,1nr|pg

If not, I don't know of a way.

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Henk Geurts
Esteemed Contributor

Re: top 3 users in a directory

du -sk * |sort -n
shows the disk usage of the directories beneath the point you run this command from.
not exactly the answer to your question but works for /home
regards.
Kent Ostby
Honored Contributor

Re: top 3 users in a directory

Rosli --

If you don't care about subdirectories then you can use this:

Create a file called "useme.awk" which contains:

{addit[$3]+=$5}
END {for (idx1 in addit) {printf ("%8s %10d\n",idx1,addit[idx1]);}}

Then do this:

ll | grep -v -e total -e ^d | awk -f useme.awk

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Noel Miranda
Frequent Advisor

Re: top 3 users in a directory

You can use the "quot" command which give the space taken up by users in blocks and sort on the block field.
Peter Godron
Honored Contributor

Re: top 3 users in a directory

Rosli,
not the quickest way I guess, but it seems to work ok.
Regards
Hein van den Heuvel
Honored Contributor

Re: top 3 users in a directory

And in perl, much similar to kent's solution but with sort build in:

while (<>){
($mode,$links,$owner,$group,$size)=split;
$total{$owner} +=$size;
}
foreach $owner (sort {$total{$b} <=> $total{$a}} keys %total) {
printf ("%12d %s\n",$total{$owner},$owner) if ($i++ < 3);
}


Hein.