Founding prices until 15 December: 30% off Pro, locked for life. See pricing

No space left on device: find what is filling the disk on Linux

Which filesystem is full, which directory is growing, which files are biggest, and the space a deleted file still holds. Five commands, with real output.

LinuxUpdated 10 November 20264 min read

A write fails with No space left on device. The fix is almost always deleting or shrinking the right thing, and the work is finding it. These steps go from "which disk" to "which file", and end with the case that confuses most people: space held by a file that no longer exists.

Everything below was run on a BrokenCluster lab machine (Ubuntu) where an app had been busy: big logs, a stray backup, hundreds of report files in /tmp, and one log someone deleted while it was still open.

1. Which filesystem is full?

The error names a file, not a disk. Ask df about that path and about the root filesystem:

$ head -c 5M /dev/zero > /tmp/export.csv
head: error writing 'standard output': No space left on device

$ df -h /tmp /
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            64M   64M     0 100% /tmp
overlay         252G   24G   19G  57% /

The root filesystem is fine. /tmp is a separate, small tmpfs (it lives in memory), and it's at 100%. That matters: cleaning /var would not have helped at all. Always check the filesystem the failing path is on.

2. What is in it?

For one directory, count the size and the number of files, then look at the newest:

$ du -sh /tmp; find /tmp -maxdepth 1 -type f | wc -l
64M	/tmp
413

$ ls -lt /tmp | head -n 4
total 65536
-rw-rw-rw- 1 student student 2981888 Nov 10 08:40 export.csv
-rw-r--r-- 1 student student  153600 Nov 10 08:40 report-412.tmp
-rw-r--r-- 1 student student  153600 Nov 10 08:40 report-411.tmp

Over 400 report files that nothing cleans up. Notice export.csv is about 3 MB, not the 5 MB that was asked for: the write stopped when the space ran out, leaving a truncated file behind. A full disk often leaves half-written files like that, so check them after you free space.

3. Which directory is growing?

On a big filesystem, walk down one level at a time. -x keeps du on one filesystem, so it doesn't wander into /proc or other mounts:

$ sudo du -xh --max-depth=1 / 2>/dev/null | sort -h | tail -n 5
1.8M	/etc
480M	/usr
601M	/opt
1.3G	/var
2.3G	/

$ sudo du -xh --max-depth=1 /var 2>/dev/null | sort -h | tail -n 3
8.2M	/var/lib
1.3G	/var
1.3G	/var/log

Repeat on the biggest entry until you reach the files. sort -h understands K, M and G, so the largest ends up last.

4. Which files are biggest?

When you'd rather jump straight to the culprits, search for large files directly:

$ sudo find / -xdev -type f -size +200M -exec du -h {} + 2>/dev/null | sort -h
350M	/var/log/shop/access.log.1
601M	/opt/backups/db-2026-11-01.sql
901M	/var/log/shop/access.log

Logs and forgotten backups are the usual suspects. Before deleting anything, ask whether it's still needed and whether something is still writing to it.

5. The space a deleted file still holds

Here's the trap. Someone deleted a 500 MB debug log to free space, but the space didn't come back. On Linux, deleting a file removes its name. The data stays until the last process that has it open closes it. du walks names, so it can't see the file; df counts blocks, so it still sees the space.

lsof +L1 lists open files with no name left (link count 0):

$ sudo lsof +L1 2>/dev/null
COMMAND PID USER   FD   TYPE DEVICE  SIZE/OFF NLINK    NODE NAME
sleep   472 root    3w   REG   0,45 524288000     0 1343644 /var/log/shop/debug.log (deleted)

Process 472 holds file descriptor 3 on the deleted log, all 500 MB of it. Either restart that process, or empty the file through its descriptor so the process keeps running:

$ sudo truncate -s 0 /proc/472/fd/3

$ sudo lsof +L1 2>/dev/null
COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NLINK    NODE NAME
sleep   472 root    3w   REG   0,45        0     0 1343644 /var/log/shop/debug.log (deleted)

Size 0: the space is back. If lsof isn't installed, the same information is in /proc: sudo find /proc/[0-9]*/fd -lname '*(deleted)'.

Free it safely

For the report files, delete by pattern and leave anything that's still being written:

$ find /tmp -maxdepth 1 -type f -name "report-*.tmp" -mmin +0 -delete; df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            64M  2.9M   62M   5% /tmp

The name pattern keeps the export out of it. -mmin +0 is an age filter set to "any age" here; on a real server use something like -mtime +1, so only files older than a day go and anything still in use stays. For a log that's still open, truncate it instead of deleting it:

$ sudo truncate -s 0 /var/log/shop/access.log && ls -lh /var/log/shop
total 350M
-rw-r--r-- 1 student student    0 Nov 10 08:40 access.log
-rw-r--r-- 1 student student 350M Nov 10 08:40 access.log.1

Deleting an open log would only have created another invisible deleted file.

When df shows free space

If writes fail while df -h shows space left, check inodes. Every file uses one, and a filesystem full of tiny files can run out of them first:

$ df -i /tmp
Filesystem      Inodes IUsed   IFree IUse% Mounted on
tmpfs          1026912     2 1026910    1% /tmp

Here inodes are fine. If IUse% is near 100%, look for directories with huge numbers of small files (find <dir> -xdev -type f | wc -l), such as caches, sessions and mail queues.

Then stop it coming back

Freeing space is the emergency fix. The real fix is what produced the files: log rotation (logrotate) for the app's logs, a cleanup job or systemd-tmpfiles rule for its temporary files, and a home for backups that isn't the server's own disk.

Questions

df says the disk is full but du shows much less. Why?
Usually a deleted file that a running process still has open. Its space isn't freed until the process closes it, and du can't see it because it has no name any more. Find it with sudo lsof +L1.
How do I free the space of a deleted file without restarting the service?
Truncate it through the process's file descriptor: sudo truncate -s 0 /proc/<pid>/fd/<fd>. Restarting the process works too, and is the cleaner fix if the program reopens its logs.
Should I delete a log file that is still being written?
No: the process keeps writing to the deleted file and the space is never freed. Truncate it instead (truncate -s 0 file), and set up rotation so it doesn't grow back.
No space left on device but df shows free space?
Check inodes with df -i. A filesystem can run out of inodes (one per file) before it runs out of bytes, usually because of millions of tiny files.

Fix it yourself

A live machine in your browser, already broken. The grader checks the result.

Start the first lab

No account needed for your first tries.

More guides