Tip: Use ‘du’ to see which subdirectories use most space

In the previous tip I showed how to use the du command to display the space used by a single directory. Often you want to find out which subdirectory is using the most space, and using the glob command and some awk scripting we can do that:

$ echo glob du '/usr/*' |
  guestfish --ro -i Fedora12 |
  awk '{if (and (NR, 1)) dir = $2; else print $1,"\t",dir; }' |
  sort -nr
1824432  /usr/share/
856092 	 /usr/lib64/
362864 	 /usr/bin/
244908 	 /usr/lib/
140824 	 /usr/include/
67948 	 /usr/libexec/
44072 	 /usr/src/
29720 	 /usr/sbin/
568 	 /usr/kerberos/
136 	 /usr/local/
4 	 /usr/tmp/
4 	 /usr/games/
4 	 /usr/etc/

Replace /usr/* with /home/* to see whose home directory is hogging all the space.

About these ads

5 Comments

Filed under Uncategorized

5 responses to “Tip: Use ‘du’ to see which subdirectories use most space

  1. GNOME and KDE both have graphical tools for this, too; it’s a good use of visualization, in fact. Baobab and Filelight, respectively.

  2. Pingback: KDE Filelight with guestmount « Richard WM Jones

  3. Why so complicated?

    What’s the difference compared to:

    du –max-depth=0 /usr/* | sort -nr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s