7 Advanced Tricks to Reclaim Disk Space for Pro Users of Mac OS X

May 10, 2013 - 14 Comments

Pro tips for advanced users to free up hard drive space in OS X Running out of disk space is never fun, and drive space comes at a premium for those of us with smaller SSD drives like the MacBook Air with a 64GB or 128GB drive. These tricks are fairly advanced and thus aimed at the pro segment of SSD users who are comfortable modifying system functions and files through the command line with potentially risky commands like ‘rm -rf’ and wildcards – if that does not describe your skill set, then this article is not for you and you should use these easy tips instead.

Also, some of these tricks disable certain system functions and may have side effects that would be considered undesirable to the average user, so be sure to understand that before using them on a given Mac. If in doubt about a specific trick or command syntax, it’s safer to avoid it completely and rely on more traditional methods offered here of reclaiming disk space when things get tight on a Mac.

WAIT! Advanced users only! Seriously. If you’re a newcomer to OS X this is not for you. One minor typo could result in file loss and damage to core OS files due to the destructive nature of the ‘sudo rm’ command. Do not use copy and paste, and be sure you have the precise path set before executing the command. Back up your Mac before you begin. You have been warned, so proceed at your own risk.

1: Disable SafeSleep Hibernation Mode

Space freed: 4GB – 16GB
This turns off OS X’s native hibernation function, known as SafeSleep. Essentially, hibernation dumps the contents of RAM to a sleepimage file on the hard disk when a Mac is put to sleep or runs out of battery. That hibernation file is the same size as your total RAM, meaning a Mac with 4GB of RAM will have a 4GB hibernation file, 8GB RAM will be an 8GB file, etc. Turning this feature off will that file from being created, thereby freeing up system RAM. The downside to this is that if a Mac runs out of battery life, you will not be able to resume instantly where things left off – in other words, keep Auto-Save enabled and save your documents when you’re nearing the end of battery life.

  • Open Terminal and enter the following command:
  • sudo pmset -a hibernatemode 0

  • Next go to /private/var/vm/ to delete the existing sleep image file:
  • cd /private/var/vm/

  • Remove the sleep image file with the following string:
  • sudo rm sleepimage

  • Still in /private/var/vm/ we must now prevent OS X from creating the file, so we’ll make a dummy and prevent write access to it:
  • touch sleepimage

  • Finally let’s prevent access:
  • chmod 000 /private/var/vm/sleepimage

This will prevent sleepimage from being created and hibernation mode from working at all. This can lead to data loss if your battery runs out and you have not saved a file recently, so be sure to keep on top of your important documents once battery life gets low.

This can be undone by deleting the new sleepimage file again, then restoring hibernatemode to “3”:

sudo pmset -a hibernatemode 3; sudo rm /private/var/vm/sleepimage

This is an advanced trick and should be treated accordingly.

2: Remove Speech Voices

Space freed: 500MB – 3GB+
Don’t use text-to-speech and don’t care about all the fancy voices included with OS X? You can reclaim a significant amount of disk space by trashing them, the total space saved depends on how many voices have been installed.

  • Back at a Terminal window, enter the following command:
  • cd /System/Library/Speech/

  • Now to delete the entire Voices directory:
  • sudo rm -rf Voices/*

Do note that text to speech will no longer function at all if you do this. It’s also possible to delete all voices using the above method, then manually add a single one if you’d prefer to retain some voice capabilities in Mac OS X.

3: Delete All System Logs in OS X

Freed space: 100MB-2GB
Log files build up over time, though ultimately how much disk space they take up depends on a variety of things like your individual computer usage, errors, what services are running, and many other things. You’ll lose the contents of apps like Console by doing this, but if you’re not interested in reading OS X log files for debugging and troubleshooting purposes this isn’t much of a loss:

sudo rm -rf /private/var/log/*

Log files will continue to generate over time, so you may want to repeat this on occasion. You could technically prevent their creation by using the same chmod approach used to block sleepimage files, but that is not recommended.

4: Delete QuickLook Caches

Freed space: 100MB-300MB
In older versions of OS X, QuickLook generated quite a bit of cache files. What’s that? Well, Quick Look is that fancy file preview ability in OS X that is summoned by selecting any file in the Finder or an Open/Save dialog and hitting the spacebar. Unsurprisingly, QuickLook relies on caching to behave quickly, and those cache files can add up. Here’s how to trash them:

NOTE: IN NEW VERSIONS OF OS X, THIS FOLDER IS NOT JUST QUICKLOOK CACHES, DO NOT DELETE THIS FOLDER IN OS X 10.10, 10.11, OR NEWER.

sudo rm -rf /private/var/folders/

5: Remove Emacs

Freed space: 60MB+
Don’t use emacs? Don’t even know what it is? You probably don’t need it then (It’s a command line text editor, for those unfamiliar). You’re not going to save GB’s with this one, but every MB helps on a small SSD:

sudo rm -rf /usr/share/emacs/

No more emacs, but don’t worry CLI users, you will still have vi and nano.

6: Delete tmp Files

Space freed: 500MB-5GB
/private/var/tmp/ is a system cache, and though it should clear itself after a reboot, it doesn’t always happen. Plus, if you have a 40 day uptime and don’t reboot often it won’t clear itself either, thus you can do it yourself. This can have unintended consequences, so this is best done freshly after a reboot, or when you quit all open applications and have no apps open or running. You’ll want to aim at the temporary files themselves that start with “TM” and not the entire directory, thus the command would be:

cd /private/var/tmp/; rm -rf TM*

Again, this can have unintended consequences, so do not do this while apps are running.

7: Trash the Cache

Space freed: 1GB-10GB+
Caches can be everything from web browsing history, to temporary app metadata, to apps very own scratch disks. Ultimately how large these user caches get depend on what apps are run, how often the Mac is rebooted, and general user activity, thus the size of these files can have a wide range. It’s not just power user apps that can grow large though, many streaming radio apps can create huge cache files that sit around for an eternity. Just like deleting tmp files, this is best done after a reboot or after quitting all open apps and thus have nothing running at the moment, or else unintended consequences could occur, resulting in strange behavior for open apps.

cd ~/Library/Caches/; rm -rf ~/Library/Caches/*

A safer approach to this is available here, which uses the Finder to delete user caches manually, thus removing the risks of using rm -rf with a wildcard.

Thanks to Fernando Almeida for providing five of these tricks! Got some awesome tips you want to share with us and the world? Hit us up on Twitter, Facebook, Google+, or email, or leave us a comment!

.

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS, Tips & Tricks

14 Comments

» Comments RSS Feed

  1. Lotte says:

    Bruce and Jason is right,

    The #4 is problematic. You SHOULD NOT delete this folder. Since I saw the translated version of this post, so it caused me an afternoon to restore and finally find this thread.

    Thanks,

    Lotte

    • imTamTam says:

      Says pretty clearly this is for advanced users of OS X, always check stuff before doing it. If you don’t know what it’s doing, don’t do it. Reading some botched translation isn’t going to be a good idea for any instructions.

    • ygnaz says:

      You’re right, and I like to confirm: # 4 surely isn’t useful: After deleting private/var/folders completely (instead of subfolders or single files), functions of ONYX 2.40 will fail. Just have tested this by recovering private/var/folders with CCCloner.

  2. unixhead says:

    Most of these tasks should be automated to run periodically. It would be nice to have an article/update on using cron or your favorite repetitive task tool.

    Also, prune by age rather than tossing today’s logs; e.g.,
    $ find /var/private/log -type f -mtime +7 -exec rm \{\} ;

    That is: find all plain files older than 7 days in /var/private/log and rm them. “7 days” is a typical value for “too old to be worth keeping any longer,” since the log information is probably stale (and backed-up, right?).

    That command goes in a crontab to run once a week, and then you should never have the problem of old, stale log files filling up disk space. Ditto for tmp, caches and similar.

  3. Bruce Hamilton says:

    #4 is not the QuickLook cache!
    /private/var/folders/ is your library, documents, pictures, etc!

    • ygnaz says:

      # 4 surely isn’t useful: After deleting private/var/folders completely (instead of subfolders or single files), functions of ONYX 2.40 will fail. Just have tested this by recovering private/var/folders with CCCloner.

  4. Thanks for this, my HD was maxing out all the time.

    Only issue I had was my computer wouldn’t start up after doing some of these. After a few hours of playing around I eventually found the culprit was step 4. After removing the /var/folders/ folder the system was failing to create files it needed for start-up.

    To solve this open up in single user mode (command + s on start-up). In the command line open up in write mode:

    mount -uw /

    Then go to /var/:

    cd var/

    Create the folder “folders” again:

    mkdir folders/

  5. AdeyJ says:

    “turning this feature off will [stop] that file from being created, thereby freeing up system RAM.”

    Can you explain how turning off a sleep image frees up RAM? Sleep images are written to system storage on a SDD, HDD or other storage device. RAM is used by the OS and applications as active memory. It is the contents of RAM that is written to a sleep image. I can not see how turning off this feature will free up system RAM.

    I am very interested to hear how this is possible.

    • Gerpstein says:

      Probably a typo. Turning off the feature frees up disk space equivalent to the size of your RAM. By the way, you should not turn of this feature. This is an “advanced” article, so it’s certainly not for everyone particularly anyone confused by how it works. In terms of RAM, when you wake a Mac from sleep that sleepimage temp file has to get loaded back into active memory to restore where you were before.

      If you’re low on disk space and have a lot of RAM, don’t use the feature.

  6. Konstantinos says:

    Hello and thanks for the tip to remove the sleepimage. However, on Mavericks 10.9.5 it doesn’t work; it keeps re-creating the sleep image upon reboot. Amazingly enough, the “chmod 000” attributes don’t even prevent this… any comment?

    I did all with needed ‘sudo’:
    sudo pmset -a hibernatemode 0
    cd /var/vm/
    sudo rm sleepimage
    sudo touch sleepimage
    sudo chmod 000 /private/var/vm/sleepimage

    • unixhead says:

      Try the following instead of a mode 000 sleepimage:

      sudo rm sleepimage
      sudo ln -s /dev/null sleepimage

      No chmod.

      Details: Makes sleepimage a “symbolic link” (alias) to /dev/null, which acts like a file, but throws away anything written to it. RAM still gets written, but at least not onto your disk. Works on my 10.8.5 MBP, “ought to work” on 10.9.

  7. steve says:

    Be careful guys: DON’T REMOVE ALL “SPEECH VOICES” unless you have a backup or unless you are really sure to never need any voices at all.

    This because if you delete all voices, then you can’t customize voices and as far as I know, you can’t restore them (unless having a backup).

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site