Deleted but open file — explain df and du disagreement
Removing one pathname does not remove other hard links. Even after the last link is removed, an open file descriptor keeps the file accessible until outstanding references are released. A rotated or removed log can therefore continue to consume space without appearing in directory walks. First establish that df and du refer to the same filesystem and account for reserved blocks, snapshots and other causes. Inspect only authorized process descriptors with lsof -a -p PID +L1; visibility depends on permissions. Check the service's documented log reopen or rotation behavior; arrange a controlled restart only when needed, preserving data and availability. Never truncate arbitrary /proc/PID/fd entries or kill unrelated processes. Verify that the service reopened the intended path, old references closed and filesystem accounting improved. Rollback: retain a verified log copy and previous rotation configuration; do not assume unlink can be undone. Prevent with tested log rotation and open-file monitoring. The fixture unlinks a private file while holding one descriptor, verifies zero links and readable data, then closes it; it does not measure physical blocks freed. Example prerequisites: Linux, Bash, Python 3. Run as a non-root user in a private temporary working directory. Example scope: native observation. Expected output: zero links; data readable until descriptor closed. No system configuration changes.
Formal Syntax & Structure
df -h -- PATH; du -x -h -- DIRECTORY; lsof -a -p PID +L1Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| df | diagnostic evidence | Filesystem allocation. |
| du | diagnostic evidence | Reachable directory entries. |
| lsof +L1 | diagnostic evidence | Open files with link counts below one. |
Return Value
Expected normalized laboratory result: zero links; data readable until descriptor closed. A passing fixture does not prove that a live incident has the same cause.
Working Example
python3 - <<'PY'import os, tempfilefrom pathlib import Pathwith tempfile.TemporaryDirectory() as d: p=Path(d)/'demo.log'; p.write_bytes(b'demo') with p.open('rb') as f: p.unlink() assert not p.exists() and os.fstat(f.fileno()).st_nlink==0 assert f.read()==b'demo' assert f.closedprint('zero links; data readable until descriptor closed')PY