There are a few tools at your disposal for checking disk space on Ubuntu 20.04 Focal Fossa. These tools and commands can be used to check a hard drive's capacity and the size of the files on it, or just to check the size of a particular directory or file.
We'll show you how to get a visual representation of how the hard drive space is being used on your system, as well as a few commands that you can enter into the terminal to quickly find the stats you need.In this tutorial you will learn:
- How to check hard drive storage with Disk Usage Analyzer
- How to check hard drive storage with Disks utility
- How to check hard drive storage with
- How to check hard drive storage with
|Category||Requirements, Conventions or Software Version Used|
|System||Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa|
|Software||Disk Usage Analyzer|
|Other||Privileged access to your Linux system as root or via the
# - requires given linux commands to be executed with root privileges either directly as a root user or by use of
Disk Usage Analyzer (GUI)
We'll start off by showing you how to get a visual breakdown of how the hard disk space is being used on your system. This is helpful in determining which directories on your system are taking up the most space. It's not uncommon for people to have a bloated directory or two that take up massive amounts of space, so what you find may surprise you.
First, you'll need to install Disk Usage Analyzer by opening a terminal and entering the following command:
$ sudo apt install baobab
Once it's done installing, you can open Disk Usage Analyzer from Ubuntu's application launcher.
When the program opens, it will ask if you want it to scan the home directory or an entire disk. Make your selection and the utility will begin scanning for files.
Once it finishes scanning for content, it'll give you a full readout of how your hard disk space is being distributed to various directories on your system. There's also a graphical representation which you can move your mouse cursor over to get an even better idea. It lists directories by size, so you can quickly determine what's chewing up the most disk space.
Disks utility (GUI)
If you're looking for a simpler tool or would like to avoid installing any software, you can always use Ubuntu's built-in Disks utility. Find it in the application launcher:
From here, you can select any hard drive in your system and then a partition to see its free space.
Check disk space from command line
You can get a quick and concise readout of the hard disk usage on your Ubuntu 20.04 system with the following command:
$ df -h
-h flag tells the command to make the sizes "human-readable." It's much easier to look at gigabyte values as opposed to bytes. The output from this command is very informative because it also shows us the size of all the mounts on our system; however, this includes psuedo file systems, such as all the
/dev/loop directories in the screenshot above.
An even better way to use the
df command is by specifying the mount point you wish to check. So to check the free space on root, you can use this command:
$ df -h /
Ah, a much cleaner output...
df is great for checking disk usage on any mount point, the
du command complements it by being able to check the storage usage on any directory - and optionally, its subdirectories. For example, here's how we'd see how much space our user's home directory is using:
$ du -sh ~
s flag in the command tells
du to just return statistics for a single directory, rather than also listing all the subdirectories. The
h flag makes the output human-readable, as discussed earlier.
Running the command without the
s flag is also very helpful, since you can see which subdirectories are taking up a lot of space. Be warned though, the output can be overwhelming if there are a lot of subdirectories, like this:
Another handy flag is
--max-depth which tells
du how deeply it should traverse into subdirectories. Use it like this (replacing 1 with any number):
$ du -h --max-depth=1 /home/linuxconfig
If you try to run
du on your root directory to see storage space across the entire disk, keep in mind that you'll need to execute that command with root privileges and you should redirect standard error to
/dev/null since you'll get a lot of "permission denied" spam in your output.
$ sudo du -sh / 2> /dev/null
In this article, we saw how to check hard disk usage via GUI and command line on Ubuntu 20.04 Focal Fossa. Both the GUI and the command line are able to give us a quick summary of storage usage, or detailed breakdowns of how storage space is being used across various directories on our system.