How do I find the largest files on a Linux server?

Run find /path -type f -size +100M to list the files above 100 MiB, or du -ah /path | sort -h | tail to see the biggest files and folders together. Add -xdev so find stays on one disk. If df says the disk is full and du cannot find the space, look for deleted files that a program still holds open with lsof +L1.

Last updated

Commands checked on Ubuntu 24.04.5 LTS (the ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b container image), .

Use find /path -type f -size +100M to list the files above 100 MiB, or du -ah /path | sort -h | tail to see the biggest files and folders in one list. Both take seconds on a small tree and minutes on a whole server, so start in the folder that the disk space article points at.

List the files above a size

The server has a data folder with a few big files. This command prints the ones above 10 MB with ls:

$ find /srv/data -type f -size +10M -exec ls -lh --time-style=long-iso {} +
-rw-r--r-- 1 dev dev 30M 2026-11-20 08:00 /srv/data/backups/db-nightly.sql.gz
-rw-r--r-- 1 dev dev 20M 2026-11-20 08:00 /srv/data/logs/app.log
-rw-r--r-- 1 dev dev 11M 2026-11-20 08:00 /srv/data/tmp/just-over.bin
-rw-r--r-- 1 dev dev 11M 2026-11-20 08:00 /srv/data/uploads/video.mp4

-type f limits the search to files. -size +10M means larger than 10 MiB. The units are c for bytes, k for KiB, M for MiB and G for GiB. Without a unit the number counts blocks of 512 bytes. The + at the end of -exec hands many files to one ls, which then sorts them by name, not by size.

To sort by size, print the size in bytes and let sort do it:

$ find /srv/data -type f -printf '%s %p\n' | sort -n | tail -3
11534336 /srv/data/uploads/video.mp4
20971520 /srv/data/logs/app.log
31457280 /srv/data/backups/db-nightly.sql.gz

Sizes are rounded up

find rounds a file’s size up to a whole unit before it compares. The folder /srv/data/tmp has one file of exactly 10 MiB and one of 10 MiB plus one byte:

$ find /srv/data/tmp -type f -size +10M
/srv/data/tmp/just-over.bin
$ find /srv/data/tmp -type f -size 10M
/srv/data/tmp/exact10.bin
$ find /srv/data/tmp -type f -size +10485760c
/srv/data/tmp/just-over.bin

The file with one extra byte counts as 11 MiB, so +10M matches it and plain 10M does not. The exact file counts as 10 and matches 10M. When the border matters, count in bytes with c, as in the last command.

See folders and files in one list

du -a prints every file as well as every folder, and sort -h puts the biggest at the end:

$ du -ah /srv/data | sort -h | tail -6
20M	/srv/data/logs/app.log
21M	/srv/data/logs
21M	/srv/data/tmp
30M	/srv/data/backups/db-nightly.sql.gz
31M	/srv/data/backups
85M	/srv/data

A folder appears with the sum of what is inside. The last line is the whole tree, and the line above it is the biggest folder in it. Read upward to find the file that makes the folder big.

Stay on one file system

A server has several file systems under one tree. find / also walks into /proc and /sys, into other disks and into network mounts. The option -xdev keeps find on the file system where each start point lives. /dev is a file system of its own, and /dev/shm is another one inside it:

$ find /srv /dev -type f -size +25M | sort
/dev/shm/dump.bin
/srv/data/backups/db-nightly.sql.gz
$ find /srv /dev -xdev -type f -size +25M | sort
/srv/data/backups/db-nightly.sql.gz

Use -xdev when one disk is full. Files on the other disks cannot be the reason, and the search gets much shorter. du has the same option, -x.

The disk is full, but no file is big

Sometimes df says the disk is almost full and du finds much less. A program may keep a file open after someone deleted it. The name is gone, so find and du cannot see it, but the space stays in use until the program closes the file. Here a program holds a 20 MB debug log on the small file system. First the numbers, then the delete:

$ df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
shm              64M   55M  9.0M  86% /dev/shm
$ du -sh /dev/shm
55M	/dev/shm
$ rm /dev/shm/app-debug.log
$ df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
shm              64M   55M  9.0M  86% /dev/shm

The file is gone and the disk is as full as before. lsof +L1 lists the open files that have no name left, because their link count is below 1. The awk part leaves out the PID, the device number and the inode, which differ from run to run. You need the PID in a moment, so the next command asks for it with -t:

$ lsof +L1 | awk '{print $1, $3, $4, $5, $7, $8, $10, $11}'
COMMAND USER FD TYPE SIZE/OFF NLINK NAME
app-worke dev 0r REG 20971520 0 /dev/shm/app-debug.log (deleted)

The program app-worker holds the file on descriptor 0 (the 0r in the FD column), and the name carries the word (deleted). A program that writes a log shows w or u after the number. You can end this in two ways. Restart the program, and the kernel frees the blocks when it closes the file. Or empty the file through /proc, while the program runs:

$ pid=$(lsof -t +L1); readlink /proc/$pid/fd/0
/dev/shm/app-debug.log (deleted)
$ : > /proc/$pid/fd/0
$ df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
shm              64M   35M   29M  55% /dev/shm

: > file writes nothing and cuts the file to zero bytes. The 20 MB came back. lsof as a normal user sees only your own processes. For the whole machine run it with sudo, and read which process uses a port for why.

Mistakes people make

You leave out the unit. -size +100 means 100 blocks of 512 bytes.

You run find / without -xdev and wait while it reads /proc.

You delete the big file and the disk stays full. Check for open deleted files before you look for more to remove.

You delete first. Print the list, read it, and only then add -delete or write the rm. Safe rm on servers has the habits that keep a wrong path from costing you a server.

You forget that logs can be big on purpose. Before you cut a log, read the end of it, as in the logs article.

The Files panel in Valakes lists a server folder and sorts it by size, and a delete there always asks first. It has no sudo, so it shows only what your login can read, and it does not replace du for a whole disk. Feature: Files

Questions

Why does find -size +100 list files of a few kilobytes?

A number without a unit counts blocks of 512 bytes, so +100 means more than 51,200 bytes. Always write the unit, for example +100M.

How do I find the biggest folders instead of files?

Run du -h --max-depth=1 on the path and sort the lines with sort -h. Repeat inside the biggest folder. The disk space article shows it step by step.

Can I free the space of a deleted file without restarting the program?

Often yes. Find the process and the file descriptor with lsof +L1, then empty the file through /proc, as in the last step of the article. The blocks come back and the program keeps running with an empty file.

References

The app is free.

Get notified at launch

macOS is coming to the Mac App Store. iOS and Android later.