OS X Terminal Taking a Very Long Time to Start

For a week now, opening a new tab or window in OS X’s Terminal application has been major palaver, sometimes taking up to a minute. CPU usage would shoot up (mostly/usually by WindowServer, but sometimes by kernel_task). It was driving me nuts. I practically live in the Terminal (or the be more accurate, Terminal + Vim), and usually spawn a new Terminal window several times in an hour for everything from using R as a calculator to opening files for viewing to actual development work. With this slow down, I found myself sometimes literally screaming in frustration: I would flick the hot key that I had bound to spawn a new Terminal window and start typing, only to realize after a half dozen characters that I might as well be watching cat videos on the internet because the window had not finished opening.

Of course, the natural suspect was my ‘~/.bashrc. It is about 1500 lines long, and, moreover sources other files. But this has been the case for years, and while I am constantly tweaking it, I could not recall making any changes in the days preceding the slow-down. More to the point, temporarily disabling this had absolutely no effect at all. Terminal still opened new windows at a tectonic pace.

I was musing reinstalling the operating system (or moving to Lion), when I stumbled upon this post:


Basically, log files build up in ‘/var/log/asl’, and this baggage causes Terminal to go catatonic during launch. Cleaning out the directory:

  $ sudo rm -r /var/log/asl/*

solved everything!

Terminal now opens new windows and tabs instantly, 1500+ line ‘.bashrc’ and all, and I am back to spawning shells as wantonly and profligately as before!

Locally Mounting a Remote Directory Through a Firewall Gateway on OS X

  1. Download and install MacFUSE.
  2. Download the sshfs binary, renaming/moving to, for example, “/usr/local/bin/sshfs“.
  3. Create a wrapper tunneling script and save it to somewhere on your system path (e.g., “/usr/local/bin/ssh-tunnel-gateway.sh“), making sure to set the executable bit (“chmod a+x“):
    #! /bin/bash
    ssh -t GATEWAY.HOST.IP.ADDRESS ssh $@
  4. Create the following script, and save it to somewhere on your system path (e.g., “/usr/local/bin/mount-remote.sh“), making sure to set the executable bit (“chmod a+x“):
    #! /bin/bash
    if [[ -n $1 ]]
    if [[ -n $2 ]]
    if test -d "$LOCAL_MOUNT"
        echo "Mount point $LOCAL_MOUNT already exists."
        echo "Creating mount point: $LOCAL_MOUNT"
        mkdir "$LOCAL_MOUNT"
    $SSHFS_PATH -o ssh_command=$SSH_TUNNEL_WRAPPER $REMOTE_HOST:$REMOTE_DIR $LOCAL_MOUNT -oreconnect,volname=$MOUNT_NAME -o local -o follow_symlinks
    if [[ $? == 0 ]]
        echo "Mounted $REMOTE_HOST:$REMOTE_DIR at $LOCAL_MOUNT"
        echo "Use \"umount $LOCAL_MOUNT\" to unmount."
  5. And the fat lady sings …

Disable OS X Time Machine’s Continuous Local Snapshot Backups

I recently emerged from a hard drive failure with minimal loss of data: between Git-mirrored project files and Apple’s built-in Time Machine backups and a little bit of luck (only a couple of hours had passed between my last Time Machine backup and the crash), almost everything was saved and restored.

With the new system, I moved to OS X Lion 10.7. While for a long time now my plan has been to move to cloud-based backup (such as SpiderOak or CrashPlan), I decided to stick with Time Machine for now. However, the implementation of Time Machine in Lion has one new “feature” that I find extremely annoying: “local snapshots“.

Basically, with this, Time Machine takes backups of your system every hour, even if your backup drive is not connected. These backups are made on your local drive, and are synced to the backup drive the next time you plug it in.

I suppose this might be useful to people who do not (extensively) use version-control to manage their work. For them, “backup” means “preserve the current version of everything I’ve got so that I can go back to it later”. I, however, have almost all my work under Git, with the local repositories mirrored in at least two other physical locations. I use the Time Machine as a convenient one-stop rescue restore solution (as opposed to the hassle of rebuilding all my local binaries, checking out the repositories one-by-one, etc. etc.), as well as the main back up for data not under version control (e.g., my e-mail and photographs). Because I explicitly take ownership of my own version-control (and I would not have it any other way), my Time Machine backups are for physical redundancy purposes, i.e., recovery in the event of hardware failure. Therefore, continuous local snapshots to the local hard drive are a waste of space and CPU time as for as I am concerned: a hard drive crash is going to take everything down anyway. (In contrast, what is useful is if the continuous snapshot backups were made to the cloud, or, as happens with Time Machine when a backup disk is actually plugged in, to a separate physical device) .

As such, I do not need, nor care for, Time Machine’s continuous local snapshot backups (with “local” referring to the local drive). But I would not have cared particularly if this was how Apple wanted to do it … if it were not for the fact that these local snapshots were taking up horrible amounts of processing power. Next time your computer gets sluggish, check your running processes (“top“, “ps aux” …. or, alternatively, for all you GUI weenies, the ActivityMonitor). You might see “mdworker”, but that’s an old and well-known periodic background CPU hog — the Spotlight index engine. But you might also see “mtmd”. This is Time Machine’s local backup engine.

After some of my gcc builds stalled for the millionth time, I decided enough was enough, and went about trying to see how to disable the local snapshot “feature”. Surprisingly, the option to do so was not built in as part of the Time Machine’s standard GUI interface. But fortunately you can do so via the command-line. This is what I do love about Apple. No matter how much the GUI parts of their operating system tends toward the fancy-schmancy “don’t-worry-your-pretty-little-head-over-that-and-just-let-us-do-your-thinking-for-you” philosophy, they almost always allow for tinkering, modification and control via the UNIX side of things. And for a command-line ex-Linux geek like me, that’s all I ask for.

So, here is how you disable Time Machine from stealing your CPU’s when you are not looking and taking local snapshots:

       $ sudo tmutil disablelocal

Voila! You have just taken ownership (and responsibility) for your backups! And that’s the way things should be.