The log was deleted. Its 48M was still allocated.

The log was deleted. Its 48M was still allocated.

●2 ●36 ●101
calendar_today • schedule1 min read

A 64M scratch tmpfs, a worker process holding its log open on file descriptor 3, and the usual reflex when space runs low: rm the log. du on the directory dropped from 48M to 0. df stayed at 48M used. The next 32M write failed with No space left on device, and df read 100% while du found only the 16M that had been written.

rm removes a name. The kernel frees the blocks only when no names are left and no process has the file open, and the worker still had it open. lsof +L1 lists exactly those files:

$ lsof -w +L1 /srv
COMMAND    PID USER FD   TYPE DEVICE SIZE/OFF NLINK NODE NAME
sleep   608657 root 3w   REG   0,78 50331648     0    3 /srv/app/worker.log (deleted)
exit=0

NLINK 0, (deleted), 48M held for writing by PID 608657. Truncating through the process's own descriptor, : > /proc/608657/fd/3, took df back to 25% while the process kept running.

Next time, empty a live log with : > file instead of deleting it. With an append-mode writer (>>) that is clean. A writer that opened with > keeps its old offset: in the same test, its log came back as a 17M sparse file with 1.0M on disk.

Finding which process holds a port or a busy mount, plus a script that groups deleted-but-open files and totals them, is on the lsof command examples page.


I bundled the scripts I copy onto every new server, plus 10 bonus ones, into the Production Bash Toolkit. 30-day refund if it isn't useful.

Want more #devops & #linux deep dives?

Join 6,029+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

2 Comments

0 votes
1

More Posts

AAIF Hits 10 Projects. Its CTO on What to Adopt Now and the Security Gaps Left Open

Tom Smithverified - Oct 23

A deploy guard that passes with no token

BashSnippets - Nov 24

My 30-day log cleanup kept a file that was 30 and a half days old

BashSnippets - Oct 8

One file more and rm deleted none of them

BashSnippets - Nov 18

I deleted 44.6 GB and df moved by 5

BashSnippets - Nov 10
chevron_left
3.8k Points • 139 Badges
North America • bashsnippets.xyz
79Posts
38Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Related Jobs

View all jobs →

Commenters (This Week)

5 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!