Skip to content

Did you know?

A deleted file keeps using disk space while a program still has it open.

Find such files with lsof +L1, then restart the program or truncate the file instead.

Explained

On Linux, deleting a file only removes its name. The data is freed when the last name and the last open file handle are gone. If you delete a 20 GB log file that a running service is still writing to, df keeps showing the disk as full, while du can’t find where the space went.

List open files that have been deleted (link count below 1):

sudo lsof +L1
COMMAND   PID   USER  FD  TYPE DEVICE    SIZE/OFF NLINK  NODE NAME
java     2318    app  4w   REG  253,0 21474836480     0 13001 /var/log/app/app.log (deleted)

To get the space back, restart or reload the program holding the file (here PID 2318). Once it closes the file handle, the space is released.

Next time, empty a large log file that is in use instead of deleting it:

sudo truncate -s 0 /var/log/app/app.log

Better still, let logrotate handle growing logs so they never get that big.

Learn more

← All tech tips · Suggest a fix

Back to top