How to Find Large Files on Ubuntu via the Command Line

When an Ubuntu server runs out of disk space, it is almost always caused by a handful of massive files. An old database backup, a forgotten zip archive, or a runaway application log file can silently consume hundreds of gigabytes, eventually crashing your services.

If you are managing the server via an SSH terminal without a graphical interface, you cannot simply open a folder and sort by size. Instead, you must use the powerful find command. Here is how to hunt down the largest files on your Ubuntu system and reclaim your storage space.

Method 1: Find Files Larger Than a Specific Size

The find command is the ultimate search tool in Linux. It can scan your entire hard drive based on highly specific criteria, including file size.

Let’s assume you want to find every single file on your server that is larger than 1 Gigabyte.

  1. Open your terminal or SSH client.
  2. Type the following command:
    sudo find / -type f -size +1G
  3. Press Enter.

Command Breakdown:

  • sudo: Runs the search with administrator privileges, ensuring it can look inside restricted system folders (like /var/log).
  • /: Tells the command to start searching at the very root of the hard drive.
  • -type f: Restricts the search to actual files, ignoring directories.
  • -size +1G: Sets the filter to find files greater than (+), 1 Gigabyte (G). You can change this to +500M for files larger than 500 Megabytes.

The terminal will output a list of file paths (e.g., /var/backups/old_database.tar.gz) that meet this criteria. You can then delete them using the rm command.

Method 2: Find the Top 10 Largest Files on the Server

The previous command is excellent for finding files over a certain threshold, but it does not tell you exactly how big those files are, nor does it rank them. To generate a true “Top 10” list of the biggest space hogs on your server, you must combine find with the sort and head commands.

Type the following command exactly as written:

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

Command Breakdown:

  • find / -type f: Finds all the files on the server.
  • -exec du -h {} +: Immediately calculates the human-readable size (Megabytes/Gigabytes) of every file it finds.
  • | sort -rh: The vertical bar (pipe) sends that list of sizes to the sort command, which arranges them in reverse order (largest at the top).
  • | head -n 10: The final pipe sends the sorted list to the head command, which cuts off the list after the top 10 results.

This combined command will take a few minutes to run if your hard drive is large, but the result is a perfectly formatted, ranked list of the absolute largest files destroying your storage capacity.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

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

Receive our best articles and tips delivered straight to your inbox.