Print directory tree disk usage on the command line

Suppose you have a large tree of directories containing lots of data (such as source code of a big project or numerical output of your simulations) and you need to estimate the total size of the whole tree. In graphical user interface this can be done by examining the directory properties. But as usual things can be done faster on the command line, where the suitable command is du (for Disk Usage).

An example (assuming that the root of your directory tree is called data)

du -h --max-depth=1 data
1.1G data/soln
3.0M data/binary
1.1G data

The -h option tells du to use human readable format, i.e. MB, GB etc instead of bytes. Option --max-depth=1 means that only the first subdirectories are listed. For more info on the options run man du.

    It is convenient to create an alias for shortening the long command such as
    alias disku='du -h --max-depth=1'
    For the alias to be present in all future sessions, add the line to your shell initialization file (for bash shell ~/.bashrc for example).

    Advertisements

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

%d bloggers like this: