Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Biggest Files on Linux: How to Find Them

· 6 min read · Home Tech

In this article
  1. Why You Need This
  2. The Core Commands: du and find
  3. Finding the Largest Directories First
  4. Using find for Size-Based Searches
  5. Common Problems and Solutions
  6. Graphical Alternatives
  7. What to Do With the Results
  8. Frequently Asked Questions

To find the biggest files on your Linux PC, use the du and find commands in a terminal. The quickest one-liner is du -ah /home 2>/dev/null | sort -rh | head -20, which lists the 20 largest files under /home by size. This article explains how that works, gives you more precise variants, and covers common pitfalls like permission errors and sparse files.

Why You Need This

Linux systems accumulate large files in predictable places: downloaded ISOs, virtual machine images, database files, log files, and user caches. Over time these can fill a disk, slow down backups, and cause applications to misbehave. Knowing exactly which files are biggest lets you decide what to delete, move to another drive, or compress. Unlike Windows, Linux has no built-in graphical "disk usage" tool in the base install, so most admins and power users rely on command-line utilities.

The Core Commands: du and find

Two classic tools do the heavy lifting:

  • du (disk usage) – estimates file and directory sizes. The -a flag shows individual files, -h prints human-readable sizes (K, M, G), and -s gives a total for each argument.
  • find – searches for files by name, type, size, or modification time. The -printf option lets you output the size and path in a custom format.

For a quick global scan, du -ah / 2>/dev/null | sort -rh | head -20 works, but it can take a while on large disks. A more targeted approach is to start from your home directory: du -ah ~ 2>/dev/null | sort -rh | head -20. The 2>/dev/null suppresses permission errors that would otherwise clutter the output.

Finding the Largest Directories First

Often you want to know which directories are huge before drilling into files. Use du -h --max-depth=1 /path | sort -rh to list one level of subdirectories by size. For example, du -h --max-depth=1 /var | sort -rh will show you that /var/log or /var/lib is eating space. Then you can descend into the biggest one and repeat. This top-down approach is usually faster than listing every file, because it avoids sorting millions of entries.

Using find for Size-Based Searches

If you already know you want files larger than a certain threshold, find is more efficient. For instance:

find / -xdev -type f -size +100M -exec ls -lh {} \;

This finds all regular files over 100 MB on the root filesystem (-xdev prevents crossing into other mounted drives). The -exec ls -lh shows sizes in human-readable form. You can also sort the output by piping to sort -k5 -rh if your ls format matches. A cleaner way is to use find with -printf:

find / -xdev -type f -size +100M -printf '%s %p\n' | sort -rn | head -20

This prints the size in bytes first, then the path, sorts numerically descending, and shows the top 20. The -size +100M accepts suffixes like k, M, G (note: M is 1,048,576 bytes, not 1,000,000).

Common Problems and Solutions

  • Permission denied errors – Many system directories are readable only by root. Adding 2>/dev/null hides the errors, but you may miss files. Run with sudo if you need a complete picture.
  • Files on other filesystems – du and find by default only scan the current filesystem. Use -xdev (or -mount on BSD) to stay on one filesystem, or explicitly include mount points like /mnt.
  • Sparse files – A file with holes (like a VM disk) may show a large logical size but use little actual disk space. du reports actual disk usage, while ls -l shows apparent size. To see both, use du -h --apparent-size file.
  • Hard links – du counts each hard link once, which is correct for disk usage. find lists every link, so the same inode may appear multiple times.
  • Sorting by human-readable sizes – sort -h (GNU) understands K, M, G suffixes. If your system lacks it, use sort -rn with byte sizes instead.

Graphical Alternatives

If you prefer a GUI, several tools give a visual breakdown. Baobab (GNOME Disk Usage Analyzer) and Filelight show pie charts or concentric rings. ncdu is a terminal-based interactive viewer that lets you navigate directories and delete files directly. These are often easier for beginners, but they rely on the same underlying du logic. Install them with your package manager, e.g., sudo apt install ncdu on Debian/Ubuntu.

What to Do With the Results

Once you have a list of large files, consider your options:

  • Delete – If it's a temporary download or old log, remove it with rm. Be certain you don't need it.
  • Compress – Use gzip, bzip2, or xz for text logs. For media files that are already compressed, you likely won't save much.
  • Move to external storage – Copy to a USB drive or network share with cp or rsync, then delete the original.
  • Clean caches – Package manager caches (e.g., /var/cache/apt) can be cleared with sudo apt clean on Debian/Ubuntu. User caches like ~/.cache are safe to delete selectively.

Always double-check before deleting anything, especially system files. A quick file command can tell you what a mysterious file is.

Frequently Asked Questions

Why does du show a different size than ls -l?

ls -l shows the apparent file size (the logical length), while du reports the actual disk blocks used. Sparse files, compression, and filesystem block sizes cause differences. For most regular files they're close, but for VM images or database files the difference can be large.

How do I find the largest files in a specific directory?

Replace the start path in the commands above. For example, du -ah /var/log 2>/dev/null | sort -rh | head -10 lists the ten biggest files in /var/log. For find, use find /var/log -type f -size +10M -printf '%s %p\n' | sort -rn.

Can I find files by size without using the command line?

Yes, graphical tools like Baobab, Filelight, and ncdu (terminal but interactive) provide a visual interface. They are often pre-installed or available in your package manager. They don't require memorizing commands.

What is the difference between du and df?

df reports free space on entire filesystems (e.g., /dev/sda1), while du estimates space used by files and directories. Use df -h to see disk fullness, and du to find what's consuming it.

Why does find -size +100M not find files that are exactly 100 MB?

The + means "greater than". To include files of exactly 100 MB, use -size 100M (without plus). To find files smaller than, use -size -100M. Note that sizes are rounded up to the next unit, so a 100 MB file might match -size 100M.

Is it safe to delete files from /tmp?

Files in /tmp are usually temporary and cleared on reboot, but some applications may rely on them during a session. It's safer to delete only files you recognize or those older than a few days. Use sudo find /tmp -type f -mtime +7 -delete with caution.