How to Check Disk and Memory Usage

This post is dedicated to checking disk and memory usage with three utilities, df, du, and free.

free is arguably the easiest of these three to use, as all it requires is a single line to display the amount of free and used memory in the system. The -m and -t switches used below convert the results to megabytes and shows a Total: row at the end.

free -mt

The output will look similar to this:

free output

free output

Note that you can also use a very popular process administration utility, htop to show you some memory usage details. See below and the post on process management basics for more information about htop.

htop

htop

df is just as easy to use as free, and I typically pass it two switches, -h and -T which, respectively, convert the output into human readable format (i.e. with k, M and G suffixes instead of everything in bytes) and displays the file type of the system (i.e. ext4, tmpfs, etc.) One parameter you may find useful occasionally is the switch -H which uses powers of 1000 vs. 1024. This can be useful because, as an example, disk manufacturers use powers of 1000 not 1024, and thus a 1TB disk is actually only read as 931.15 GB.

df -hT

The output will look similar to this:

df output

df output

du is the last up, and while still easy to use, is slightly more complicated. du is a utility that estimates the size of files (and directories). As usual, you will want to pass it the -h switch so the output is in human readable format. Below are a couple of common ways to use du.

To find out the total size of the current directory including all sub-directories, issue the command:

du -hs
du summary output

du summary output

To find out the sizes of each of the directories including all sub-directories, issue the command:

du -h
du full listing output

du full listing output

To find out the sizes of each of the top level directories including all sub-directories (but not list them individually), issue the command:

du -h --max-depth=1
du top level output

du top level output

As one last note, remember that you can use sort to sort the output by size. For example:

du -h | sort -hr
du full listing sorted by size

du full listing sorted by size

Tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

Protected by WP Anti Spam