Jump between directories with zoxide
Install zoxide, load it in bash, zsh or fish, jump with z and zi, import your autojump or z history, and replace cd with --cmd cd.
Updated
in short
Install zoxide, add zoxide init to the end of your rc file, then type z plus part of a directory name. Add fzf for the zi picker, and use --cmd cd if you want zoxide behind the plain cd command.
zoxide records the directories you visit and ranks them by how often and how recently you used them. z proj then jumps to the highest-ranked directory matching "proj", wherever it is.
This guide installs it for bash, zsh and fish, covers the z and zi commands, imports history from autojump or z, and shows how to make cd itself use zoxide.
Tools used
Before you start
- bash, zsh or fish (zoxide also supports PowerShell, elvish, tcsh, xonsh, any POSIX shell and others)
- A package manager such as Homebrew, pacman, dnf or winget, or
curlfor the install script - fzf 0.51.0 or newer if you want
ziand interactive completions
Steps
Step 1: Install zoxide
Install it from your package manager or with the project's install script. The project advises against the Debian and Ubuntu
aptpackages because they lag far behind; use the script on those distributions.sh# macOS or Linux with Homebrew brew install zoxide # Arch Linux sudo pacman -S zoxide # Any Linux, macOS or WSL, official install script curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | shsh# Windows winget install ajeetdsouza.zoxideStep 2: Load zoxide in your shell
Add the line for your shell to the end of its rc file. In zsh it must come after
compinit, or completions will not work.bash# ~/.bashrc eval "$(zoxide init bash)"zsh# ~/.zshrc eval "$(zoxide init zsh)"fish# ~/.config/fish/config.fish zoxide init fish | sourceStep 3: Jump with
zOpen a new shell and keep using
cdfor a while so zoxide can learn your directories. It adds a directory every time you change into it. Then usezwith one or more keywords. Matching ignores case, every keyword has to appear in the path in order, and the last keyword has to match the final directory name, soz barfinds/foo/barbut not/bar/foo.zalso accepts normal paths,..and-, so you can use it in place ofcdfor everything.shz proj # highest-ranked directory matching "proj" z work api # matches "work" and then "api" z ~/code # a normal path, like cd z .. # one level up z - # previous directoryStep 4: Pick interactively with
ziInstall fzf, then run
ziwith an optional keyword to choose from every match in a fuzzy list. In bash 4.4+, zsh and fish you can also typez projfollowed by a space andTabto get the same picker as a completion.shbrew install fzfshzi projStep 5: Import history from autojump or z
If you used another directory jumper, import its data so you do not start from zero. zoxide 0.10.0 and newer find the data file on their own; supported sources are
autojump,z,zsh-z,z.lua,fasdandatuin. Add--mergeif your zoxide database already has entries, otherwise the import stops with an error.Older releases (0.9.x) take the source as
--fromand need the data file path, and only supportautojumpandz.sh# zoxide 0.10.0+ zoxide import autojump --merge zoxide import z --mergesh# zoxide 0.9.x zoxide import --from z ~/.z --mergeStep 6: Replace
cdwith--cmd cdThe
--cmdflag renames the commands.--cmd cdmakescdthe jumping command andcdithe interactive one, so existing habits and scripts that callcdin your interactive shell go through zoxide. Change the init line you added in step 2.--cmd jwould give youjandjiinstead.bash# ~/.bashrc eval "$(zoxide init --cmd cd bash)"zsh# ~/.zshrc eval "$(zoxide init --cmd cd zsh)"fish# ~/.config/fish/config.fish zoxide init --cmd cd fish | sourceStep 7: Inspect and clean the database
zoxide queryshows what zoxide has learned. Usezoxide removefor directories you never want to jump to. To keep directories out entirely, set_ZO_EXCLUDE_DIRS(colon-separated globs on Linux and macOS) before the init line.shzoxide query --list --score projshzoxide remove ~/old/projectshexport _ZO_EXCLUDE_DIRS="$HOME:$HOME/private/*"
Troubleshooting
zoxide: no match found: the directory is not in the database yet.cdinto it once, or runzoxide add <path>.- zsh prints "zoxide: detected a possible configuration issue": something after the init line replaced zoxide's hook. Move
eval "$(zoxide init zsh)"to the very end of~/.zshrc. - Tab completion does nothing in zsh: the init line runs before
compinit. Move it below, then runrm ~/.zcompdump*; compinitto rebuild the cache. zifails or shows no picker: fzf is missing or older than 0.51.0. Check withfzf --version.zoxide import autojumpis rejected: your zoxide is older than 0.10.0. Use the--fromform with the data file path, or upgrade.
Tips
_ZO_ECHO=1prints the matched directory beforezjumps to it._ZO_FZF_OPTSpasses extra options to fzf forzi. Like the other_ZO_variables, set it beforezoxide init.- Several file managers and terminal session managers read the zoxide database, so the same ranking follows you there.
Also worth a look
FAQ
- Does --cmd cd break scripts that use cd?
- Not in bash or zsh: scripts run in a non-interactive shell that does not read ~/.bashrc or ~/.zshrc. fish reads config.fish for scripts too, so put the init line inside an if status is-interactive block.
- Where does zoxide store its database?
- In $XDG_DATA_HOME or ~/.local/share on Linux, ~/Library/Application Support on macOS and %LOCALAPPDATA% on Windows. Set _ZO_DATA_DIR before zoxide init to change it.
- Do I need fzf?
- Only for zi and the Space-Tab interactive completions. The z command works without it.