The cd command is a fundamental tool for navigating the filesystem in Unix-like operating systems. While indispensable, for those who spend a significant amount of time in the terminal, repeatedly typing long directory paths can become tedious.

A powerful alternative, zoxide, offers a more intelligent and efficient approach to directory navigation. It is a command-line tool that monitors your directory usage, enabling you to jump to frequently accessed locations with minimal typing. Its ability to learn your habits and predict your intended destination makes it a significant improvement over the traditional cd command. For anyone who relies heavily on the terminal, zoxide is a game-changer that streamlines your workflow.

Setting Up Zoxide

Zoxide is readily available on all major Linux distributions and macOS. You can find the installation instructions for your specific system here .

After installation, you must add one of the following lines to your shell’s configuration file (e.g., .bashrc or .zshrc):

For bash:

eval "$(zoxide init bash)"

For zsh:

eval "$(zoxide init zsh)"

ℹ️ Note: If you are using some other shell, view the installation instructions for your specific shell in the zoxide installation link above.

Once you have completed this step, zoxide will be ready to use. This script initializes zoxide and sets up the z command for changing directories and zi for an interactive directory selection menu.

To maintain the muscle memory developed from years of using cd, I recommend creating the following aliases:

alias cd='z'
alias cdi='zi'

How It Works

For the remainder of this post, any mention of cd will refer to the z command, and cdi will refer to the zi command, as per the aliases established above.

cd

You can begin using zoxide immediately. Navigate to directories as you normally would with cd, and zoxide will automatically track your usage. The more frequently you visit a directory, the higher its ranking becomes in zoxide’s database.

To jump to a directory, simply type cd <directory_name>. Zoxide intelligently matches your input with the directories you have visited and navigates to the most relevant one.

For instance, if you are working on a project located at ~/dev/my-awesome-project, you can navigate to it once using the full path. Subsequently, you can simply type cd my-awesome-project, cd awesome, or even cd aw, and zoxide will take you there directly, provided there are no other directories that more closely match the input. This feature significantly reduces the time and effort required to navigate your filesystem, especially for deeply nested directories.

zoxide use

cdi

The cdi command provides an interactive way to select a directory. It uses the fuzzy finder tool fzf to display a list of your most frequently used directories, ordered by their rank.

While I personally use the cd command more often, cdi is particularly useful when you have multiple directories with similar names or when you want a quick overview of your recent locations.

When you execute cdi, a list of directories appears, with the most frequently used ones at the top. You can use the arrow keys to navigate the list and press Enter to jump to the selected directory.

Please note that to use cdi, you must have fzf installed on your system. You can find the installation instructions for fzf here .

Closing Thoughts

Zoxide has made my terminal experience significantly more efficient and enjoyable. If you spend a substantial amount of time working in the terminal and frequently change directories, I highly recommend giving zoxide a try.

For a visual demonstration of zoxide, I suggest watching this video by Dreams of Autonomy, which is where I first discovered this invaluable tool.