Skip to content
All articles

How to find large files on Ubuntu

When an Ubuntu server is running out of space, I start by finding the filesystem that is filling up. Then I look for either a few large files or a directory full of smaller ones.

Check the free space

df -h
df -h -- /var

The second command reports the filesystem that holds /var. It helps you pick the right place to search, especially when directories such as /home or /var are on separate mounts.

Find files larger than 400 MiB

find /var -xdev -type f -size +400M -print

-type f selects regular files and -xdev keeps the search on the starting filesystem. With GNU find, the M suffix means MiB. Choose the directory that corresponds to the filesystem you found with df. If permissions prevent the scan from reaching some directories, the result covers only the paths your account can read.

To leave out a particular directory, prune it before applying the file filters:

find "$HOME" -xdev -path "$HOME/.cache" -prune -o \
  -type f -size +400M -print

Rank the largest files

find /var -xdev -type f -size +400M -printf '%s\t%p\0' |
  sort -z -nr |
  head -z -n 10 |
  numfmt -z --field=1 --to=iec-i --suffix=B |
  tr '\0' '\n'

Sort the raw byte counts first, then format them for display. The commands pass NUL-separated records, so spaces in filenames survive the pipeline. The final tr is for terminal display. A filename that already contains a newline can still appear across multiple lines in that display.

See which directories use the most disk space

du -x -h --max-depth=1 -- /var | sort -hr
du -sh -- "$HOME"

The first command includes the total for /var as well as its immediate subdirectories. Rerun it inside the largest subdirectory to narrow things down. The second command gives you a single total for your home directory.

find ranks files by their apparent size. By default, du reports the space allocated on disk. A sparse disk image can therefore appear near the top of the file list and still account for much less disk usage in the directory totals.

See the GNU Findutils manual and the GNU Coreutils documentation for du.