How to Find Large Files and Directories in Ubuntu via the Terminal

Running out of disk space on an Ubuntu system can cause services to fail, updates to break, and unexpected system crashes. Finding what is consuming your disk space is the first step to resolving the issue.

Checking Total Disk Usage

Before diving into specific directories, check your overall disk usage to confirm which partition is full. You can do this quickly from the terminal.

Open your terminal and run the following command:

df -h

The -h flag makes the output human-readable (showing megabytes and gigabytes). Look for the Use% column, particularly for your root partition (usually mounted at /).

Finding the Largest Directories

If your root partition is full, you need to find out which folders are consuming the most space. The du (disk usage) command is the best tool for this.

Run the following command to see a summary of the largest directories in the root filesystem:

sudo du -h --max-depth=1 / | sort -hr

This command does three things:

  • du -h --max-depth=1 / calculates the size of the top-level directories in root.
  • sort -hr sorts the output by size, with the largest directories at the top.
  • sudo is required so the command can read protected directories.

Identifying Large Files

Once you identify a large directory (for example, /var), you can drill down further by changing the path in the previous command:

sudo du -h --max-depth=1 /var | sort -hr

If you want to find the largest individual files anywhere on your system, you can use the find command:

sudo find / -type f -exec du -h {} + | sort -hr | head -n 20

This will list the top 20 largest files on your entire Ubuntu installation, helping you quickly track down massive log files, unused ISOs, or large media assets.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.