macos – Why does even `rm` refuse to operate with insufficient disk space, and how do you *really* delete files in that situation?

Spread the love


I have macOS High Sierra – 10.13.6 Security Update 2020-006 (17G14042) and my system is not behaving well due to the disk being full of data.

I try to keep a few GB free on my Mac’s HD but occasionally it suddenly gets full for reasons beyond my control (some swap file randomly gets larger perhaps?). Then the system deadlocks – files cannot be saved, the Finder becomes unresponsive (even when force-relaunched), some other applications become unresponsive, and some of the ones that do respond are unable to quit cleanly (presumably because that would involve writing to files). I’d like to save my unsaved work by first clearing disk space without having to hold down the power key.

The first thing I do is force-quit browsers but that alone doesn’t solve it. I typically still have Terminal open and am able to switch to it. There, using df and du I can see that maybe 1-2G could be freed from ~/Library/Cache or ~/Downloads. However, when I try to remove files using rm, e.g.:

rm -rf ~/Library/Cache/Google

or:

rm -f ~/Downloads/biggest_single_file.blob

…then the rm utility itself refuses, with the message “No space left on device”. To me this is surprising – why would a utility whose sole purpose in life is to remove files need to consume disk space? It’s like saying “You’re too thirsty to drink,” or “Let’s not turn on the heater, it’s too cold,” – in other words, ridiculous.

I’m guessing the explanation must be that rm, even though I’ve been thinking of it as a low-level utility, is really doing something more complicated involving versioning or backups or journaling or something that requires a file to be created. If so: is there an even-lower-level command for truly just deleting files?

Update: I guess whatever over-clever thing is consuming disk space must actually be a property of the filesystem rather than necessarily the rm utility. I got the same error message if I tried

echo "" > ~/Downloads/biggest_single_file.blob

or

python -c "open('$HOME/Downloads/biggest_single_file.blob','wt')"

Author: Dhanraj7978

Leave a Reply

Your email address will not be published. Required fields are marked *