Tools to Monitor Disk Usage

The linux command line provides several utilities to monitor disk usage. To see disk usage for each file system, use the following:

$ df -Th

The T flag tells df (disk free) to list the file system types. The h flag tells df to show the numbers with human-readable suffixes such as G for gigabyte and M for megabyte.

To see the disk usage for a specific directory, use the following:

$ du -hd1

The h flag again makes the numbers human-readable. The d flag tells du how detailed it should list per-directory folder sizes. A value of 1 tells du to list the size of the directory and its subdirectories.

To get a more detailed list, omit the d switch.

$ du -h

To view disk usage for another directory, append the directory path:

$ du -hd1 log

If there is not a / at the beginning of the directory path, it is assumed to be relative to the current directory.

To skip certain types of files such as *.mp3 files or *.tmp files, use the –exclude switch:

$ du --exclude='*.mp3'

The stat command returns information about a file, including the last time it was accessed, the last time it was modified, its ownder, its permissions, and its size. Use the following:

$ stat /var/log/apache2/access.log

Stat can also be used on directories, but it will not recursively compute the size of its subdirectories.