How to Find Large Files in Ubuntu Terminal

Running out of disk space on a headless Ubuntu server is a common administrative headache. When an application crashes due to a “No space left on device” error, you need to rapidly identify which files or directories are consuming your storage.

Without a graphical file manager, pinpointing bloated log files, forgotten database dumps, or massive media archives requires the terminal. Using native Linux utilities like find and du, you can quickly scan your entire file system and sort the results by size.

Method 1: Using the ‘find’ Command

The find command is the most precise tool for locating individual files that exceed a specific size threshold. It searches the directory tree recursively and outputs the exact paths.

To find all files on your system larger than 500 Megabytes, open your terminal and run:

sudo find / -type f -size +500M -exec ls -lh {} + | awk '{ print  ": "  }'

Understanding the command:

  • sudo: Runs the command with root privileges, ensuring it can search protected system directories.
  • /: Instructs the command to start searching from the root directory. You can change this to a specific path, like /var/log.
  • -type f: Restricts the search strictly to files, ignoring directories.
  • -size +500M: Filters the results to files larger than 500MB. You can use G for Gigabytes (e.g., +1G).
  • -exec ls -lh {} +: Executes the ls command on the found files to display human-readable sizes.

Method 2: Using the ‘du’ Command to Find Large Directories

Sometimes, the storage issue is not a single massive file, but rather a directory containing thousands of smaller files (such as a cache folder or a node_modules directory). The du (Disk Usage) command is perfect for calculating directory sizes.

To list the largest directories within your current location, run:

sudo du -aBM 2>/dev/null | sort -nr | head -n 20

Understanding the command:

  • du -aBM: Calculates disk usage for all files and directories, outputting the sizes in Megabytes (M).
  • 2>/dev/null: Silences “Permission denied” errors, keeping the output clean.
  • sort -nr: Sorts the output numerically (n) in reverse (r), placing the largest directories at the top.
  • head -n 20: Limits the terminal output to the top 20 results so it does not overwhelm your screen.

Method 3: Using ncdu (Recommended)

If you prefer an interactive, visual approach within the terminal, ncdu (NCurses Disk Usage) is a highly recommended third-party utility. It provides a navigable interface where you can drill down into folders using your arrow keys.

Install it using the package manager:

sudo apt update
sudo apt install ncdu

Launch it by typing:

sudo ncdu /

The application will scan the disk and present a clean, sorted list of directories. You can press the Enter key to enter a folder, and the d key to delete a highlighted file immediately.

Get the best tech tips delivered straight to your inbox.

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