Skip to content

Recover Linux Disk Space Held by Deleted Files

Admin
November 20, 2026
5 min read
Intermediate
💻 Target OS: Ubuntu 26.04 LTS / RHEL 10

Before you begin

  • Applies to:Linux hosts where deleted files may still be held open by running processes.
  • Where to start:Open a shell on the host that reports the full filesystem. Start with the path where writes failed.
  • What you need:Use an approved account with sudo access and lsof installed. Identify the service that owns the files. The examples use /var. Substitute the actual mount point reported in Step 1.
Guide tools
Guide tools
0/0 Steps (0%)

Troubleshooting Steps

01

Identify the full filesystem

Start here

Use the actual path where writes failed. Compare space and inode usage. Resolve the filesystem’s mount point even if the path itself is just a directory on root. Compare with visible file usage only on the same filesystem. Snapshots, hidden data beneath mounts, and filesystem accounting can also explain a discrepancy.

Terminal window
findmnt --target /var -o TARGET,SOURCE,FSTYPE
df -h -- /var
df -i -- /var
02

Find deleted files that are still open

Use the exact mount point from the previous output. The +aL1 form selects unlinked files on that filesystem. A nonzero status can mean no matches or a diagnostic error, so review stderr and permissions. Multiple processes or descriptors may refer to the same device and inode. Avoid adding their sizes together.

What you should see · The listing shows the PID and file descriptor for unlinked files on the affected mount.

If you see something else · If no candidates appear and there are no command errors, go to Step 6 for other explanations. If a candidate appears, confirm its device, inode, and link count in Step 3 before asking the process owner to release it.

Terminal window
sudo lsof -nP +aL1 /var
03

Identify the process and confirm the file

Substitute the PID and numeric descriptor from lsof, omitting suffixes such as w. Verify on the same host before acting because PIDs and descriptors can be reused. For a regular file, link count 0 confirms it is unlinked. Allocated blocks can differ from the apparent file size.

Terminal window
pid=1234
fd=5
ps -p "$pid" -o pid,ppid,user,comm
sudo stat -Lc 'links=%h inode=%i size=%s blocks=%b block_unit=%B' "/proc/$pid/fd/$fd"
04

Choose the least disruptive release

For a log file, check if the service supports reopening its logs and whether rotation hooks were missed. For a database or unfamiliar data file, involve the service owner and determine whether the file must be preserved. If reopening is unavailable, schedule an approved restart or failover. All holders of that file must release it before the storage can be reclaimed.

05

Compare space and service activity after recovery

Rerun df for the same filesystem and the scoped lsof check. Confirm the original device and inode are gone from the listing, the service works, and application logs go to the intended active file. A different process or inode may still be retaining space.

Terminal window
df -h -- /var
sudo lsof -nP +aL1 /var
06

Resolve any remaining discrepancy

If the original open file is gone but space is still low, check other holders, filesystem snapshots, reserved space, and data hidden beneath mounts. Record the before and after measurements and correct rotation or service logging only after establishing the original cause.

Decide What to Do Next

FindingNext action
Large regular file, zero links, open descriptorCoordinate an approved reopen or restart with the process owner.
Several rows share a device and inodeIdentify every holder and count the file only once.
No matching records with sufficient accessContinue with filesystem-specific space accounting.

References

Comments