How to Find Large Files in Linux Using the Command Line

Every system administrator eventually encounters the dreaded “No space left on device” error. When an Ubuntu server runs out of disk capacity, databases crash, web servers fail to restart, and background scripts abruptly terminate. Unlike a desktop computer where you can simply open a graphical file manager and sort a folder by size, managing a headless Linux server requires a completely different approach. To quickly restore system functionality, you must learn how to find large files in Linux using the command line.

Using the find Command

The find utility is one of the most powerful and flexible search tools available in Unix-like operating systems. It allows you to search for files based on highly specific criteria, including their exact file size.

To locate all files on your entire system that are larger than 1 Gigabyte, open your terminal and execute the following command:

sudo find / -type f -size +1G

Let us break down exactly what this command is doing:

  • sudo: Runs the search with root privileges, ensuring you do not get “Permission denied” errors when scanning restricted system directories.
  • /: Instructs the search to begin at the absolute root directory of your server and scan everything downward. (If you only want to search your personal home folder, replace / with ~/).
  • -type f: Restricts the search specifically to files (ignoring directories and symbolic links).
  • -size +1G: The core filter. It tells the system to only return files larger (+) than 1 Gigabyte. You can easily modify this to +500M for 500 Megabytes, or +10G for 10 Gigabytes.

Displaying the File Size in the Results

While the previous command successfully lists the file paths, it does not actually show you how large the files are. To print the file sizes in a human-readable format alongside the paths, you can pipe the output into the ls command:

sudo find / -type f -size +1G -exec ls -lh {} +

This will return a detailed list, allowing you to instantly identify a massive 50GB forgotten backup file or a rapidly expanding error log.

Using the du (Disk Usage) Command

While find is excellent for locating specific, gigantic files, it is less useful if your disk space is being consumed by thousands of small files hidden inside a specific directory. To identify which directories are hogging the most space, you should use the du command.

Navigate to the root directory (cd /) or the directory you suspect is full (e.g., cd /var/log), and run:

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

Here is how this command pipeline works:

  • du: Initiates the disk usage tool.
  • -h: Outputs the sizes in human-readable formats (K, M, G).
  • --max-depth=1: Prevents the command from recursively printing every single subfolder, limiting the output to the immediate top-level directories of your current location.
  • | sort -hr: Takes the output from du and sorts it numerically from largest to smallest, ensuring the biggest folders are printed at the top of your screen.

Common Culprits and Safe Deletion

When you locate a massive file, do not immediately delete it without understanding what it is. Deleting core system libraries will instantly brick your server.

Typically, the largest space hogs are found in:

  • /var/log/: Applications like Nginx, Apache, or MySQL can generate massive text logs if log rotation is not properly configured. You can safely delete or truncate old .gz archived logs.
  • /var/cache/apt/archives/: Ubuntu stores cached installation packages here. You can safely clear this folder by running sudo apt clean.
  • User Home Directories: Forgotten Docker images, old website backups, or massive SQL dumps are frequently left in personal user folders.

To safely delete a file you have identified as useless, use the rm command:

sudo rm /path/to/massive_file.log

By mastering find and du, you can confidently diagnose storage issues and restore a failing Linux server in a matter of seconds.

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.