Z

I spend fair amount of time on the command line, and one of the most useful tools I’ve come across is a little script called ‘Z’. Here’s what it does in a nutshell:

  1. Intercepts call to cd and keeps track of where you’re cd‘ing to, when, and how often.
  2. Provides a z command that accepts a flexible regex syntax and will cd to the best directory based on Z’s “frecency” algorithm:

Frecency is a portmanteau of ‘recent’ and ‘frequency’. It is a weighted rank that depends on how often and how recently something occurred. As far as I know, Mozilla came up with the term.

To z, a directory that has low ranking but has been accessed recently will quickly have higher rank than a directory accessed frequently a long time ago.

Frecency is determined at runtime.

It works great. It guesses correctly the vast majority of the time. Certain directories become hot for a while depending on what a person is working on, and Z effectively uses that pattern to jump to the correct location. What I like best about the operation is that when the target is something like: /Volumes/HD/dev/personal/web/foo/bar/blah/stuff/yay/whatever, I can usually type z what and get to where I need to go.

The other aspect that I really like is the simplicity. Installation is a one line addition your .bashrc/.zshrc file, and using it is nothing more than using cd like you normally do for a while until it figures our where you want to go.

Use it.