Why Deleting Large Files Doesn’t Free Disk Space on Linux and How to Fix It
When a huge file is removed on a Linux server but the root partition still shows 100% usage, the issue is usually caused by the file being held open by a process, reserved filesystem space, or delayed space reclamation, and can be resolved with commands like lsof, kill, or tune2fs.
Problem Description
A server’s root partition reached 100% usage after an 80 GB file was deleted with rm -f, yet the space was not released.
Cause Analysis
In Linux, deleting a file only removes its directory entry (unlink). If a process still has the file open, the inode remains in use, so the data blocks are not freed and df still reports full usage.
File storage consists of metadata (pointers) and data blocks. When a file is deleted, the metadata is cleared, but the data blocks stay allocated until no process holds the file.
Remediation Steps
Use lsof | grep deleted to list deleted files still held open, then terminate the offending processes (carefully, as killing processes may affect services).
Stop or restart the application that was using the deleted file so the OS can reclaim the space.
Reboot the system as a last resort.
For log files that are continuously written, truncate the file (e.g., echo " " > /home/wangshibo.log or cat /dev/null > /home/wangshibo.log) to free space without stopping the process.
Example of Truncating a Log File
echo " " > /home/wangshibo.log</code>
<code>cat /dev/null > /home/wangshibo.log</code>
<code>> /home/wangshibo.logAdditional Disk‑Space Issue
Sometimes df -h shows ample free space, but creating or writing files fails with “no space left on device”. This is often due to deleted files still occupying space.
Typical workflow:
Run df -lh to identify the problematic partition.
Locate the partition (e.g., /data).
List deleted but still‑open files: lsof -n /data | grep deleted.
Kill the processes holding those files:
lsof -n /data | grep deleted | awk '{print $2}' | xargs kill -9.
Verify no deleted files remain with another lsof check.
Reserved Space on ext Filesystems
Ext2/3/4 reserve a default of 5 % of the filesystem for privileged processes. This can appear as wasted space. Adjust with tune2fs -m 2 /dev/vda1 to set the reservation to 2 % (not recommended to set to 0%).
tune2fs -m 2 /dev/vda1</code>
<code>Setting reserved blocks percentage to 2% (209704 blocks)After running the command, the root partition freed about 1 GB, confirming the reservation change.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
