2 min read

Give your mac some relief: how to remove the sleepimage file using Terminal

Your mac, depending on how you have it set up and how you use it, can slow on start up from restarts or hibernation due to the presence of a very large file called “sleepimage”. This is a very important file generated by Safe Sleep (on all MacBook Pros, for example) that serves the purpose of saving a state of your mac’s memory that keeps you from losing data when the computer sleeps, hibernates, restarts, or runs out of memory. However, once you’re up and running again, this file is no longer needed and it can be a substantial draw on memory causing your mac to exhibit less than optimal performance, including noticeably slower performance.

Disabling Safe Sleep is a bad idea in my opinion, and thus not an option. Fortunately, you can easily free memory on your machine for more important files related to your papers and evolutionary analyses, by removing the sleepimage file. The coolest way to do this from the mac OS X command line, i.e. Terminal window, as a “super user”. Do this by typing the following command string into a Terminal window:

sudo rm -rf /var/vm/sleepimage

Enter a carriage return to send the command to your mac, then you will be prompted to enter your super user password, so put it in and press enter again. Voila! Your sleepimage file is gone forever (that is, until it is regenerated again during sleep etc.). Check the size of your mac’s hard drive (e.g. default name of the correct place to look is “Macintosh HD”) before and after performing this procedure to “see” how much space removing sleepimage frees up for you. For me, this is typically on the order of 8-10 Gb of data, so it’s a substantial gain in space!! This demonstrates how you can use the “rm” (remove) command to delete files permanently (see more on this UNIX command here, here, and here). However, exercise caution with this, like everything else you do from the mac command line, because you can just as easily and accidentally wipe out a whole section of your hard drive if you follow this little command with the wrong path!

I do the procedure discussed above every time I sleep my MacBook Pro with multiple programs open, and it’s helped me a lot, so I hope you find it helpful as well. Cheers.

~J