About | ACP | Buy | Industry Watch | Learning Curve | Search | Test Drive
Home » Learning Curve

Keep a Clean Machine

'He likes to keep his fire engine clean, it's a clean machine.'

Get It

Try It

'Some Mac users may want to clear caches and clean out temporary files', writes OS X Daily in the understatement of the year. And whilst the tutorial is good for showing you where to find junk, theirs is a rather laborious process to repeat all the time.

Here's an idea! Make a shell script to automate it for you! And for goodness sake don't make an Automator thing - just make a good old-fashioned shell script! So easy!

Here we go. We'll follow OS X Daily...

1. Quit out of any actively open Mac apps

Not sure what a passively open app would be, but OK. Not sure either you have to quit anything, but heck. OK.

2. Go to the Finder in Mac OS

Uh NO. And where else would you find Finder but in 'Mac OS'? OK, OK.

3. Hold down the OPTION / ALT key and pull down the 'Go' menu in the Finder
4. Choose 'Library' from the Go menu options

Yes, that's cute, isn't it? A directory in your own private area - and now Apple don't want you going there anymore? Screw 'em. They can't stop you. Fix that first.

5. Once inside the Library folder, find and open the 'Caches' folder

Ah! You wanna go there? Why didn't you say so!

6. Choose which caches and temporary files to clear, you can selectively choose specific app caches and temporary files to clean, or select them all, then place those cache items into the Trash

OK, you might want to look over what you have there, but keep two things in mind:

  1. OS X Daily's not coming with any recommendations; and
  2. Caches are caches. They're caches! They're meant to save time! Like with your browser, right? So if the app in question can't find its caches, guess what it will do? That's right - it'll just keep calm and carry on.

So heck - delete the lot!

And if you have a more sensical file manager, you can skip step 7.

OS X Daily goes on to mention 'web browser caches', and yes, it can be easier - even sufficient - to use the web browser itself to do this. But don't assume the programmers think the same way you do, or even that they're as smart as you. Find out where your browser stores its junk by using a decent utility like Tracker (yes a free version) and then target those locations in a shell script.

OS X Daily goes on to say that a system reboot will clean system caches, but this is only partially true. Once again, assuming you can use a better file manager, look at this:

The cute stuff is under /var/folders. One subdirectory is yours, the other belongs to the system. (No, you can't get at the system's caches without privilege escalation, why would you want to?) Your own directories here should be:

Cleanup At Startup

The stuff under '0' is for your own good, so leave it alone. Here you'll find launch services caches, and you generally want them. For example. The 'C' stands for - get ready, hold on! - CACHES! So YES, you can obliterate anything here, all of it, go ahead, don't worry, no privilege escalation, just do it! Now 'Cleanup At Startup' sounds good, sounds almost like instructions for cleanup at startup? So leave it alone. But 'T' - you'll never guess what that stands for! Again: don't mess with the 'zz' subfolder.

(Ten points if you can figure out why it's named 'zz'.)

And of course you'd like to clean out here:

But forget it. That monster doesn't stop.


Now then. The easiest way to do this the second time, the third time, and so on is to amalgamate it all. Put it into a script. And the easiest way to go about that is to pick what you want gone and then go to it.

This particular step may take time, but it won't take longer than you need to follow the original OS X Daily tutorial.

  • You want to get at ~/Library/Caches/*. Go in and see what you want gone. Or just opt to remove it all.
  • You might want to get at your own /var/folders directories. Go in and see what path they use - don't take 'zz'.
  • You might want to see where Safari spreads its litter and add that as well. Use Tracker.

And so forth.

Let's take the simplest form of that script.

rm -fr ~/Library/Caches/*
rm -fr /private/var/folders/<??><??????????????????????????????>/C/*
rm -fr /private/var/folders/<??><??????????????????????????????>/T/*

Or we could put it all on one line.

rm -fr ~/Library/Caches/* /private/var/folders/<??><??????????????????????????????>/C/* /private/var/folders/<??><??????????????????????????????>/T/*

But for now, let's make three separate commands, and we can amalgamate them later if we like the results.

And now, pursuant to you deciphering the actual path components <??> and <??????????????????????????????> by inspecting your own system, we can pull out the secret snake oil weapon.

Click the above icon to download. It's CLIX, the Command Line Interface for OS X, and all it's going to do is give you a way to save those commands of yours for easy future access.

My Very First CLIX File

You're going to create a CLIX file of your own, your very first CLIX file, and it's going to take you all of two minutes. Then, in the future, when you want to clean your machine, you won't need to revisit that OS X Daily link again, won't need ten minutes or more to get things done. Starting now, the process will take only seconds. Good deal?

OK, here we go.

  1. Open CLIX.zip. Inside you'll find the directory CLIXSierra. This is the latest build of a utility dating back more than ten years. It's super-secure and essentially it just makes it easier to use raw Unix commands, and with no tangible overhead.

  2. Drill down into CLIXSierra. And you'll find the CLIX app. You can put it anywhere you want. We recommend you make your own ~/Applications directory and not add to the confusion of /Applications. (You can do that later.)

  3. Launch CLIX.

  4. The CLIX document window has four columns. Title, Category, Description, Command Line. All columns save the last are completely arbitrary, although certain conventions apply. Sorts for the first two columns are nested with each other.

  5. Choose Edit-Add from the menu or hit ⌥⌘-Enter. A command sheet will pop down.

  6. You'll tab through the four fields to enter text. For 'Title', put 'Clean Library Caches'. For 'Category', put 'Maintenance'. For 'Description', put 'clean out caches in Library'. And for 'Command Line', put 'rm -fr ~/Library/Caches/*'.

  7. Click 'Save' to close the sheet, then choose File-Save to save your CLIX document as 'My Very First CLIX File.clix'.

  8. Now do the same for the other two commands. Then save your CLIX file again.

  9. Double-check your work before 'going live'. For example, create the directory ~/Library/Cuches, copy in ~/Library/Caches, then temporarily modify and run the corresponding command. Make sure it works as you'd expect.

Postscript: TMO's 'Terminal Commands'


A few things to add.

  • pwd - stands for 'print working directory'. Yes, back in THOSE days, everything was printed. This is one of the ways the commands are cryptic. (The other reason is Ken likes cryptic and sparse. Deal with it.)

  • cd - cd alone with no arguments returns you to your home directory (~). Stands of course for 'change directory'. Dennis had a great tale about how the duo spent months debugging their kernel because cd wasn't working. A mind-blowing read if you can find it.

  • sudo - stands for 'substitute user and do', not 'superuser' as some think. Superuser is default but not the only option. sudo is preferable to su as you normally can execute a single command and GTFO. Reduces risk of being piggybacked. Use 'sudo -s' to create a new shell, end the new session with 'exit'. sudo is maintained in Theo de Raadt's OpenBSD. Apple's version is not always up to date. Watch out - the black hats do.

  • defaults - one of the most important NeXTSTEP programs. Typical of how NeXT took a leaping jump over the entire industry. Learn this command and learn how NeXTSTEP works, much as learning ls teaches you the essentials of Unix. When messing with defaults, try to remember to first determine what a setting's default value is before parameters are added to the system, and if there are no such parameters in your preferences, then revert your setting by removing rather than adding a new value. Reduce clutter, bump your system performance.

  • killall - follows on kill but takes a process name rather than a process ID. Command name implies it will 'kill all' processes matching a name. Takes further arguments before the process name, such as the strength of the kill. Use '-9' for full obliteration. And you can 'sudo' this as well for additional efficacy.

Postscript: Uninstalling Applications


For notes on removing apps, see the Tracker files. You should make a habit of always tracking an app (and archiving the track record) before letting it go and trusting it. If you find a developer's system that's sloppy, you've found a sloppy developer.

There are a thousand places you can check for junk. If you'd like a tutorial on a particular aspect of keeping your machine clean, drop a line.

See Also
Xfile: Free Test Drive
CLIX: Learn How to Fish

About | ACP | Buy | Industry Watch | Learning Curve | Search | Test Drive
Copyright © Rixstep. All rights reserved.