Operations 4 min read

How to Locate and Release Disk Space from Deleted Open Files on Linux

When disk usage reported by df doesn't match du and inodes are not full, the discrepancy often stems from files that were deleted while still held open by running processes, and this guide explains how to identify those processes and safely free the space.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Locate and Release Disk Space from Deleted Open Files on Linux

In routine Linux operations, disk‑space alerts may reveal a mismatch between df (showing high usage) and du (showing lower usage). If df -i indicates that inode usage is normal, the most likely cause is a large file that has been removed but is still referenced by a running process.

Why the space is not released

When a process keeps an open file descriptor to a file that has been deleted, the file's data blocks remain allocated until the process terminates or closes the descriptor. Consequently, the occupied space is not reclaimed, leading to the observed discrepancy.

Finding the process that holds the deleted file

Linux exposes all open file descriptors under /proc/*/fd. Deleted files appear with the label (deleted) in the symlink target. The following command lists every such descriptor: sudo find /proc/*/fd -ls | grep '(deleted)' Sample output:

388609 0 lrwx------ 1 zerotier-one zerotier-one 64 Aug 21 00:19 /proc/29400/fd/4 -> /tmp/ibpX85Vd\ (deleted)
388610 0 lrwx------ 1 zerotier-one zerotier-one 64 Aug 21 00:19 /proc/29400/fd/5 -> /tmp/ibCwAgAj\ (deleted)
388611 0 lrwx------ 1 zerotier-one zerotier-one 64 Aug 21 00:19 /proc/29400/fd/6 -> /tmp/ibRZ5rep\ (deleted)
388612 0 lrwx------ 1 zerotier-one zerotier-one 64 Aug 21 00:19 /proc/29400/fd/7 -> /tmp/ibBuNEzA\ (deleted)
388616 0 lrwx------ 1 zerotier-one zerotier-one 64 Aug 21 00:19 /proc/29400/fd/11 -> /tmp/ibG68kpG\ (deleted)

Each line shows the PID (e.g., 29400) and the file descriptor that points to a deleted temporary file. Stopping or restarting the offending process will release the space.

Preventing the issue

Instead of deleting a large file outright, truncate it so the filesystem frees the blocks while the process keeps the file handle open. Two common truncation methods are: cat /dev/null > ${filename} or the more concise Bash syntax: : > ${filename} Both commands replace the file's contents with zero bytes, instantly freeing the occupied disk space without needing to terminate the process.

Reference

Find and remove large files that are open but have been deleted.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

operationsLinuxdisk spaceFile ManagementDeleted Files
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.