Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Ditch cd: Use Powerful Linux Tools for Fast Navigation

· 7 min read · Home Tech

In this article
  1. Why cd Feels Slow
  2. The Main Tools and How They Work
  3. How to Install and Set Them Up
  4. Practical Examples and Workflows
  5. Common Problems and Misconceptions
  6. Choosing the Right Tool for You
  7. Performance and Resource Use
  8. Safety and Data Considerations
  9. Frequently Asked Questions

Yes, you can ditch cd for many everyday tasks and use powerful Linux tools like z, autojump, fasd, and fzf to navigate directories at warp speed. These tools learn your habits or let you fuzzy-search paths, so you jump to a folder with a few keystrokes instead of typing long paths or repeatedly pressing cd ...

Why cd Feels Slow

The built-in cd command is simple and universal, but it has real limitations. It requires you to know the exact path, type it fully (or use tab completion), and it has no memory of where you go often. In a deep project tree like /home/you/work/projects/client-xyz/src/components, you either type the whole thing, rely on tab completion, or create symlinks. None of these scale well when you switch between five or six directories constantly.

Modern shells add conveniences like cd - to go to the last directory, but that only remembers one place. The tools below solve the deeper problem: they remember your history, rank directories by frequency and recency, and let you jump by name or fuzzy pattern rather than by path.

The Main Tools and How They Work

Several popular tools exist, and they fall into two broad families: frequency-based jumpers and fuzzy finders.

  • z (also zoxide, a Rust rewrite) – tracks directories you visit, assigns a score based on frequency and recency, then lets you jump with z proj to the most likely match. You can pass multiple arguments to narrow down, like z proj src.
  • autojump – similar concept, uses j command. It maintains a database in ~/.local/share/autojump/ and supports tab completion for matches.
  • fasd – combines file and directory jumping. You can use z for directories, f for files, and even v to open a file in Vim.
  • fzf – a general-purpose fuzzy finder. When paired with a shell integration, you can press a key (like Ctrl+T) to interactively search files and directories, or use Alt+C to jump into a selected directory.

All of these work by hooking into your shell's chpwd or PROMPT_COMMAND to log your current directory after every command. The data stays on your machine; nothing is sent externally.

How to Install and Set Them Up

Installation is straightforward on most Linux distributions. For example, on Debian/Ubuntu you can install autojump with sudo apt install autojump. For zoxide, use curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh or your package manager if it has it. fzf is often available as sudo apt install fzf.

After installation, you need to add a line to your shell startup file (~/.bashrc for Bash, ~/.zshrc for Zsh). For zoxide, add eval "$(zoxide init bash)" (or zsh). For autojump, it's . /usr/share/autojump/autojump.sh on Debian. For fzf, add source /usr/share/doc/fzf/examples/key-bindings.bash if you want the key bindings. Then reload with source ~/.bashrc.

One caveat: these tools only start tracking after you install them. So you need to visit your important directories once normally (with cd) to build the database. After that, the scores adjust automatically.

Practical Examples and Workflows

Here's how a typical session looks with zoxide (using z command):

  1. You often work in /var/www/html/site. After visiting it a few times, you can type z site and it takes you there.
  2. If you have two directories named site (e.g., ~/work/site and /var/www/html/site), z site will pick the one you visit most often. To force the other, type z site www or use the full path.
  3. With fzf, press Alt+C to get an interactive list of directories under your current location. Start typing a few letters, press Enter, and you're there.
  4. Combine fzf with cd by using cd $(find . -type d | fzf) – this lets you fuzzy-search any subdirectory.

These tools shine in monorepos or when you have many similarly named projects. Instead of remembering ~/work/company-2024/backend/api-gateway, you just type z api and it jumps.

Common Problems and Misconceptions

One frequent issue is that the tool doesn't seem to remember directories. This usually happens because the shell hook isn't loaded correctly, or you're using a shell that isn't supported (like fish without the proper init). Check the startup file syntax and ensure the tool's binary is in your PATH.

Another misconception is that these tools replace cd entirely. They don't; they complement it. You still need cd for one-off paths, absolute paths, or when you want to go to a directory that isn't in your history. Also, they only work for directories you've visited before. A brand new directory won't be in the database until you enter it once.

Some users worry about privacy. These tools store your directory history locally, usually in a plain text or SQLite file. If you're on a shared machine, that history is visible to other users with read access. You can disable tracking for sensitive directories by configuring ignore patterns in the tool's config file.

Choosing the Right Tool for You

Which one should you pick? It depends on your workflow:

  • zoxide – best if you want a modern, fast, and actively maintained tool. It works across Bash, Zsh, Fish, and even PowerShell. It also has a zi command to interactively select a match.
  • autojump – a solid choice if you prefer a simpler, older tool with a large user base. It's often pre-installed in some distributions.
  • fasd – useful if you also jump to files frequently, not just directories. It has a lightweight footprint.
  • fzf – not a jumper per se, but a powerful fuzzy finder that can be used for directories, files, command history, and more. It's a great addition to any setup, even if you already use z.

You can also combine them. Many users run zoxide for quick jumps and fzf for interactive searches. There's no harm in using both.

Performance and Resource Use

These tools are lightweight. They run a simple command after each cd (or each prompt) to update a database. The overhead is typically a few milliseconds, imperceptible in interactive use. The database files are small – a few kilobytes to a few megabytes depending on how many directories you visit. For example, zoxide uses a SQLite database that stays compact even after months of use.

If you're on an extremely slow system or have a huge number of directories (tens of thousands), you might notice a slight delay when z searches. But for normal use, it's negligible.

Safety and Data Considerations

Since these tools modify your shell behavior, you should understand what they change. They add a function that wraps cd or hooks into the prompt. In rare cases, a misconfigured hook can cause errors in scripts that rely on cd output. However, the tools are designed to be transparent; they don't alter the actual directory change, only record it.

If you ever want to reset the database, you can delete the data file (e.g., ~/.local/share/zoxide/db.zo for zoxide, ~/.local/share/autojump/autojump.txt for autojump). The tool will recreate it on the next use. There's no risk of data loss beyond losing your jump history.

For security, avoid using these tools on a shared system if you're concerned about revealing your directory structure. Otherwise, they are safe and widely adopted in the Linux community.

Frequently Asked Questions

Does zoxide work with fish shell?

Yes. Zoxide has built-in support for fish. You just add zoxide init fish | source to your ~/.config/fish/config.fish file. The same command works for Bash and Zsh with the appropriate shell name.

Can I use fzf to jump to a directory without installing anything else?

Yes. Fzf alone can provide directory jumping via the Alt+C key binding. It lists subdirectories of your current location, not your entire history. To search your entire history, you need a jumper like zoxide or autojump.

Why does z sometimes take me to the wrong directory?

The scoring algorithm favors frequency and recency. If you have two directories with similar names, it might pick the one you visited more often. You can override by typing more characters to disambiguate, or use z -i to see a list of matches and select interactively.

Are these tools available for macOS?

Yes, most of them are cross-platform. Zoxide, autojump, and fzf all work on macOS via Homebrew (brew install zoxide, brew install autojump, brew install fzf). They integrate with the default Zsh shell.

Will these tools slow down my terminal?

No. The overhead is minimal – a few milliseconds per command. The database operations are optimized and happen asynchronously in some cases. You won't notice any lag in normal typing.