Display top ten directories by size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display top ten directories by size
# 1  
Old 06-30-2009
Display top ten directories by size

Hi,
I am new to Unix.
I want to display top 10 folders by size.
I tried with
du -ksl * | sort -nr | head -10
command .But I am getting the following error

-bash: /usr/bin/du: Argument list too long

Can some one help me.
Thanks.
# 2  
Old 06-30-2009
if you have Python on your system, you can try this script (example 5).
# 3  
Old 06-30-2009
use the below code:-


Code:
df -ah | nawk '(NR>1){match($3,"[0-9]*.[0-9]*") ; print r=substr($3,RSTART,RLENGTH)}'| sort -r | head -10

I working in the below system:-

SunOS server8 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Blade-100


or in a more general form use:

Code:
df -ah | nawk '(NR>0){match($3,"[^.]*.[^.]*") ; print r=substr($3,RSTART,RLENGTH)}' | sort -r | head -10


Last edited by ahmad.diab; 06-30-2009 at 10:50 AM..
# 4  
Old 06-30-2009
Quote:
Originally Posted by ahmad.diab
use the below code:-


Code:
df -ah | nawk '(NR>1){match($3,"[0-9]*.[0-9]*") ; print r=substr($3,RSTART,RLENGTH)}'| sort -r | head -10

I working in the below system:-

SunOS server8 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Blade-100


or in a more general form use:

Code:
df -ah | nawk '(NR>0){match($3,"[^.]*.[^.]*") ; print r=substr($3,RSTART,RLENGTH)}' | sort -r | head -10

df? Whatever this produces doesn't work on Solaris 8 or on AIX (and I'm guessing Linux either).

What operating system are you using, Satyak? I would guess AIX (or Linux) as "du -ksl" doesn't work on Solaris.

If you are using AIX, and you're able to, you can increase the arg list limit:

For example:
Code:
chdev -l sys0 -a ncargs=128

(or the equivalent for your OS)
# 5  
Old 06-30-2009
use du -ksl, not du -ksl *. Almost same, but not for du.
du | sort -nr | head -10

Heavy diskusers ?
Code:
ls -alR | awk '
   /^-/ { users[$3]+=$5 } # take regular files only

   END {
        for (user in users) {
                print user,users[user]
                }
       }
  ' | sort -t " " -k 2,2nr | head -10

# 6  
Old 06-30-2009
If you are only interested in total size of directories in current directory (including any subdirectories under those directories):

Code:
find "`pwd`"/* -prune -type d -print 2>/dev/null|xargs du -ks|sort -nr|head -10

Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies

2. UNIX for Dummies Questions & Answers

top ten utilities in shell scripting?

Let's get some feedback about the top ten ute's you guys use in writing your scripts - I mean yeah it depends on the job and what you're trying to accomplish, but there ARE those commands (sed, grep, awk, cut, etc.) that most will use time and again... ...so, what do you use? (3 Replies)
Discussion started by: diego
3 Replies
Login or Register to Ask a Question