Disk free results not updated after removing files


We have a web server which has %100 disk usage on some partitions because of the webserver logs.

When I delete some of the log files with rm command to free up disk space, nothing changed on output of the df command.

But, if I use file truncate pattern like : > log_file_name, specified log file is truncated and disk usage percentages in output of df command updated as expected.

Why disk free, disk usage numbers not updated after removing of files?


rm command removes specified file name from the directory entries, so you can’t see that file name after remove. But it doesn’t actually delete the file contents.

Deleting file contents is the responsibility of kernel. If deleted file has any hard links or already opened by a process, its contents not removed.

You can check a file is already opened by a process or not with lsof command like below:

$ sudo lsof -n | grep filename

In your setup, webserver still keeps open file descriptors. If you restart the webserver, file contents will be deleted and df shows correct numbers.