Command line tips - checking a folder’s disk usage with du

Konqueror is one of my favourite file managers on any platform (add OS X's Finder column view and it would be the best). Why? Well, amongs many other features, it has a view called File Size View, that allows you to see how much space folders and files are taking up visually, and makes it really easy to see what files need cleaning up and deleting.

While I don't know a way to do the visual thing from a command line interface, you can do a similar thing with checking file sizes, using du.

Run it on its own, and it will just list the size (in bytes) of all directories inside the current working directory (to an infinite level of detail). In fact, there are quite a few configuration options for it, so if you can decipher it, it's worth reading the man page.

$ du

It's not always easy to work out file sizes in bytes though, so a useful switch to remember is -h.

$ du -h

That will show you nice friendly file sizes. Again, the output from running the command can be huge (especially if you're in a folder with lots of subfolders), so you might want to pipe the output to less.

Alternatively, you could limit the maximum number of subfolders du will traverse with the --max-depth switch:

$ du -h --max-depth=3

There are also a ton of other configuration options, so do be sure to explore du yourself!

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Command line tips - checking a folder’s disk usage with du

  1. Pawel (guest)

    # Posted on 02 April 2007 at 02:59 AM

    It should be: du -h --max-depth=3



  2. Pawel (guest)

    # Posted on 02 April 2007 at 03:02 AM

    It doesn't show the double "-"



  3. Peter (guest)

    # Posted on 02 April 2007 at 03:11 AM

    Thanks for pointing that out, Pawel.

    WordPress had very helpfully converted the double dash to a longer single dash, which in this context, wasn't very helpful.

    It should be fixed now.



Home » Articles » Command line tips - checking a folder’s disk usage with du