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

  • April 2, 2007
  • Avatar for peter
    Peter
    Upfold

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

Home » Articles »