check ubuntu disk space

Certain programs like VLC can sometimes write very large-sized logs causing the disk space to fill up quickly. 

This is a common scenario, but even if you don’t have a similar problem, it’s still important to keep track of your disk usage.

There are both GUI and CLI tools for checking the disk space status, meaning there’s more than one way to get the job done.

Check Space with Disk Utilities

We’ll start with some built-in GUI applets. The simplest one is the System Monitor. In the Filesystems tab, you’ll find the currently mounted devices along with the Used and Available disk space.

The Disks utility allows you to check the disk usage. Additionally, you can view unmounted partitions from here. You can also perform other disk-related tasks like formatting the partition or resizing the filesystem from this utility.

Finally, there’s the Disk Usage Analyzer. As the name implies, this tool lists file locations along with the used disk capacity in a ring chart. You can also switch to a treemap chart if you want. Either way, it’s useful for finding out which files are occupying the most space. 

Use df and du (CLI)

The df command displays the amount of disk space available on all currently mounted file systems. You can use it without any options too, but using the human-readable and total flags will yield a better result.

df -h --total

There are a couple of easy ways to track down files that are occupying high disk space. First, you can use du with the threshold option to only show files above a certain size. For instance, to show files larger than 1GB only, you could use

du -h --threshold=1G  | sort -h

Alternatively, you could scan the top-level child directories in root. This’ll list the contents of root along with the space occupied.

sudo du -x -h -d1 /

One common scenario is that /var occupies an unexpected amount of space. There are likely a lot of obsolete log files stored there. So, you could now scan /var, and so on.  

sudo du -x -h -d1 /var

You’d keep this process going until you arrive at the exact files you want to remove. It’s similar to the Disk Usage Analyzer, except this one is CLI-based.

Check Disk Space with ncdu

ncdu is a curses-based disk usage analyzer. If the du utility felt too roundabout for understanding the disk space usage, but you still want a CLI-based tool, ncdu is a good option.

Install it, cd to the root directory, and launch ncdu as shown below.

sudo apt install -y ncdu
cd /
ncdu

Now, use the arrow keys to switch the selections or move between directories. You can also press q to quit, or ? to bring up the help pop-up. It’ll list shortcuts for various functions like sorting the results, deleting files, changing the display format, and so on.

Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.