How To Check Disk Space Usage in Linux


This guide shows different ways to check disk or storage space usage on a Linux system via the graphical user interface(GUI) and the command line.

Why check disk space usage?

The amount of available disk or storage space dramatically determines how your Linux system and the software installed on it, run. You need to ensure that there is adequate space for you or running services to create or store files. If your system runs out of reach, you may not create new files or store files on it. Besides, running applications may be unable to create or store files, thus not running as expected or ultimately terminating with an error message.

Therefore, keeping an eye on disk space usage helps to ensure that your Linux system has adequate space for the entire system to run well.

Check Disk Space Usage using GUI Applications

On a Linux desktop system, you can use the default GUI application for your distribution. For example, on a Linux mint system, search for Disk Usage Analyzer from the system menu, then open it. For each partition, the application will show the total space and used space as shown in the following screenshot.

Check disk space usage on Linux Mint desktop

On Ubuntu desktop, you can search for the Disk Usage Analyzer application from the Activities menu and open it.

Check disk usage on Ubuntu
Check Disk Space via the Command Line

You can also check disk space usage from a terminal window using the following command line interface tools.

Check File-system Disk Space Usage Using df

df is a commonly used text-based tool for viewing disk space usage on Unix-based systems such as Linux operating systems. It shows each file system and its total size, amount of space used, amount of space available, percentage of space used, and mount point.

To use it, open a terminal window or log into your server via ssh, then run this command:

Run df command without any arguments

You will notice that when run without any options, df will display disk space in space in 1K blocks by default. To enable df to display disk space in a human-readable format, use the -h option like this:

#df  -h
Display df command output in human-readable format

To enable df to print the file system type(for example EXT2, EXT4, etc.) for each partition or file system, add the -T option, like this:

#df   -hT
Display file system type in df output

For more usage options, see the df man page like this:

#man df
Check Files and Directories Disk Space Usage Using du

du is another useful text-based tool for reporting disk space usage on a Linux system. Unlike df which we have looked at above, du shows you the amount of disk space used by files and directories.

By default, if you don’t specify any arguments, it will show the disk space usage of all files and sub-directories in the current directory.

Run du command without any arguments

You can also specify a directory as an argument so that du will show the disk space usage of all files and sub-directories in it. In this example, I have specified the root(/) directory.

#du /

To show file and directory sizes in human-readable format, add the -h option:

#du -h /
Specify a directory as an argument to du

A better way to use du is to combine it with other command-line tools such as sort and head. The sort tool will help sort the output and the head command sets a limit on the number of lines to display. The following are some examples.

In this example, du shows an error if it can’t find files and directories in pseudo file systems(such as /proc). To avoid this error, use the -x option(which enables du to skip directories on different file systems) as shown in the next command:

#du -h / | sort -rh | head -5
du command error about missing files and directories

Let’s break down the next example. In the next command, du checks for files and sub-directories in the /var directory. The out is filtered through the sort command where the -r enables the sort command to reverse the result of comparisons and -h enable it to compare human-readable numbers.

Finally, the output from sort is filtered through the head command and only the first five lines are displayed.

#du -hx /var | sort -rh | head -5
Filter du command out through sort and head commands

For more usage options, check the du man page:

#man du
Check Docker Disk Space Usage

On a Linux system running docker, you can check the disk space usage of docker objects using the following command:

#docker system df
Check disk space usage of Docker objects

For more information, check out: How To Free Up Disk Space From Docker Overlay2


That’s all I prepared for you in this guide. If you have any questions or comments to share about this post, kindly use the feedback form below. Also, feel free to share this guide with the Linux community.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Page Contents