How-to check for large directories (or files) in linux

5/9/2007; 8:56 AM

The du command will give you a listing of the disk usage of each different file in the current directory. Without any parameters du will list the number of bytes in each directory. This is hardly very useful but if combined with the sort command the output will be sorted by from smallest to largest files.

Some useful parameters for du
-a: will list file size as well as directories
--max-depth=: allows you to specify the subdirectory level depth
-h: report the figures in KB, MB and GB instead of bytes (does not work well with sort)

Some useful parameters for sort
-n: sort based on numbers rather than characters (i.e. 10 comes after 9)
-r: reverse sort. display the largest number first.

Examples of using du
du | sort -rn | less (reverse sort the output displying one screen at a time)
du --max-depth=2 | sort -n (display and sort only down 2 directories)
du -a | sort -n (display all files not only directies)
du -ch --max-depth=1 /home (display the size of all the directories in the /home directory and display the total size used by /home)

Logon

Fill out the form below to logon to this site, or sign up below.

Username (email address):
Password:
I forgot my password; please send me a new one.
 

Signup

Fill out the form below to join as a member of this site.

Screen name:
Email address:
Password:
Repeat password:
Homepage (optional)