z is a utility that allows you to jump around your machine very quickly. It allows you
to change directory by specifying a partial path and it will choose the most relevant one based on your directory
history automatically. It uses an algorithm that’s based on “frecency”. Directories are ranked by how frequently you
visit them, and how recently the last visit was.

It’s a bit tough to explain, so here’s an example. I spend most of my time working in three directories:

  • /var/www/example.com/main/src/application
  • /var/www/example.com/main/src/tests
  • ~/testing/storyplayer/main/src/

Instead of typing cd /var/www/example.com/main/src/application every time I want to work on “example.com”, I just
need to cd into it once, and it will add it to my list of visited paths in z. The next time I want to work in that
folder, I can just type z example and it will jump to the correct path.

Where it gets tricky is when I mean to go to /var/www/example.com/main/src/tests, but z thinks I want to go to the
application folder. Fortunately, z lets you specify multiple search values, so if I type z example and it takes me to
the application folder, I can just type z example test to jump to the tests folder.

If you try and move to a directory that doesn’t exist, then z just won’t do anything.

# We want to work on "example.com"
vagrant:~$ z example

# We didn't mean the application (even though we normally do)
# So let's change to the tests directory
vagrant:/var/www/example.com/main/src/application$ z example test

# You don't have to specify a full word, just the shortest 
# string that will match will do
vagrant:/var/www/example.com/main/src/test$ z storypl

# Let's try and change to a directory that we've never been to
vagrant:~/testing/storyplayer/main/src$ z foobar

# Nothing happened, we're still in Storyplayer
vagrant:~/testing/storyplayer/main/src$ ‚Äč


z on Github

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply