The swapfile items you should not touch as they are part of the core structure of the Mac OS X system; similar swapfiles exist on other Unix/Linux systems. But the
sleepimage file can be safely deleted as long as you know what it does and what functionality you will lose if you remove/disable it.
Basically, in “old school” sleep mode, if you had applications open and then put your Mac to sleep and then the Mac lost power, it would have been as if you ripped the power cord out of the wall. Meaning the state of all of the apps would be nullified and your work would disappear into the digital ether.
But the new type of sleep mode (aka: “hibernate mode”) uses
sleepimage to add a safety net if you need it. Meaning, when you go to sleep on a Mac that supports it (depends your system; more details in this answer), the system will save a snapshot of your system (aka: what is in RAM) to the hard disk in a
sleepimage file. That way if your Mac loses power, your work application state and related work is saved to disk. So when the machine powers up again, guess what? The
sleepimage is loaded into RAM and you are back to normal again.
Sounds cool, but it’s only really useful for portable Macs like the MacBook, MacBook Pro, MacBook Air, etc… For someone like me—who works on a desktop-based Mac Mini—it’s fairly useless since I am plugged into AC power all the time. So when I did a recent system rebuild and saw an 8GB
sleepimage file taking up valuable space, I got rid of it. And here is how you can do that as well; first check to see what
hibernatemode is set to on your system:
pmset -g | grep hibernatemode
One of the three option settings you should see are:
- 0: Old school sleep mode with no safety net. Best for desktops.
- 3: Hibernate sleep mode with the
sleepimage safety net. Will keep RAM powered while sleeping for fast wake. Best for portables.
- 25: Hibernate sleep mode with the
sleepimage safety net. Powers down RAM during sleep and will always wake up by loading
sleepimage. Best for portables and saves power/battery life by not sending power to RAM chips.
Now knowing that if you want to disable it, you now run this command to set
sudo pmset -a hibernatemode 0
With that done, ditch the
sudo rm /private/var/vm/sleepimage
And that frees the space. But there is still a risk of it being recreated in the future; during a system update for example. So this is how you can ensure the
sleepimage file is never recreated. First create a zero length placeholder for the
sudo touch /private/var/vm/sleepimage
Now change set the “immutable” flag on the file to ensure it never gets written to:
sudo chflags schg /private/var/vm/sleepimage
With that done,
sleepimage should be removed, space reclaimed and the risk of
sleepimage being recreated is eliminated. But like I said, if you are using a portable Mac and rely on sleep mode, disabling this is not advised.