List pr. command in megabytes sum of deleted files that are still in use and therefore consumes diskspace

lsof -ns | grep REG | grep deleted | awk '{a[$1]+=$7;}END{for(i in a){printf("%s %.2f MB\n", i, a[i]/1048576);}}'

By: atboy
2015-01-22 13:03:48

What Others Think

Hmm... Interesting. I'd make a few simple changes. First, combine the two greps: ... | grep "\<REG\>.* (deleted)$" | ... Next, I'd add a count of the deleted files awk '{b[$1]++;} and I'd pipe the output into column to make it more legible ... | column -t lsof -ns | grep "\<REG\>.* (deleted)$" | awk '{a[$1]+=$7;b[$1]++;}END{for(i in a){printf("%s %d %.2f MB\n", i, b[i], a[i]/1048576);}}' | column -t You could also sort the result: ... | sort -k3 -n
flatcap · 352 weeks ago
Why not just use awk? lsof -ns | awk '/REG/&&/deleted/{a[$1]+=$7;}END{for(i in a){printf("%s %.2f MB\n", i, a[i]/1048576);}}'
lowjax · 347 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: