Why Deleting Large Files Doesn’t Free Disk Space on Linux and How to Fix It
When a large file is deleted on a Linux server but the '/' partition still reports 100% usage, a running process likely still holds the file open, preventing space reclamation; this article explains the cause, shows how to find deleted‑but‑in‑use files with lsof, and offers recovery steps such as killing processes, restarting services, truncating logs, and adjusting reserved block percentages.
Problem Description
A server in an IDC showed the '/' partition at 100% usage after an 80 GB file was removed with rm -f. The df -h output confirmed the full usage:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
58G 7.8G 47G 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/vda1 190M 72M 108M 40% /bootRoot Cause Analysis
In Linux, deleting a file only removes its directory entry (unlink). If a process still has the file open, the inode and data blocks remain allocated, so the space is not reclaimed. The kernel keeps the file’s metadata until the last reference is closed.
Common Remedies
Use lsof | grep deleted to list deleted files that are still held open, then safely terminate the offending processes. This method can be risky if many critical processes are involved.
Stop or restart the application that was using the deleted file, allowing the OS to free the space automatically.
Reboot the operating system (least preferred).
For log files that are continuously written, truncate the file in place so the process can continue logging while the space is released.
Truncating a Log File In‑Place
# echo " " > /home/wangshibo.log
# cat /dev/null > /home/wangshibo.log
# > /home/wangshibo.logAnother Disk‑Space Symptom
Sometimes df -h shows ample free space, yet creating or writing a file fails with “no space left on device”. This usually stems from deleted files that still occupy space.
Step‑by‑Step Recovery for a Specific Partition (e.g., /data)
Run df -lh to identify the partition with unexpectedly high Used space.
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 results remain with the same lsof command.
Note that after killing processes, df -h may temporarily show a spike in used space, which gradually shrinks as the kernel releases the blocks.
Reserved Space on ext Filesystems
Ext2/3/4 reserve about 5 % of the filesystem for privileged processes. On large disks this can waste space. The tune2fs command can adjust the reservation, but setting it to 0 % is discouraged for safety.
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/vda1 ext4 41151808 4962148 34076228 13% /
devtmpfs devtmpfs 1931468 0 1931468 0% /dev
tmpfs tmpfs 1941204 0 1941204 0% /dev/shm
tmpfs tmpfs 1941204 652 1940552 1% /run
tmpfs tmpfs 1941204 0 1941204 0% /sys/fs/cgroup
tmpfs tmpfs 388244 0 388244 0% /run/user/0
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 4.8G 33G 13% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 620K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0To reduce the reserved space to 2 %:
# tune2fs -m 2 /dev/vda1
Setting reserved blocks percentage to 2% (209704 blocks)After the change, the '/' partition shows the reclaimed space:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 4.8G 34G 13% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 620K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 380M 0 380M 0% /run/user/0These steps help ensure that disk space is correctly reclaimed after file deletions and that reserved blocks are tuned to avoid unnecessary waste.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
