Skip to content

Zoxide

Zoxide is a smarter cd command, inspired by z and autojump. It remembers which directories you use most frequently, so you can "jump" to them in just a few keystrokes. Zoxide works on all major shells.

What is Zoxide?

  • Smart cd replacement that remembers your most-used directories
  • Works like autojump/z.sh but faster and simpler
  • Learns as you use it - no manual bookmarking needed

Installation

For Windows (PowerShell):

sh
winget install zoxide

Basic Setup

Add this to the end of your shell config file (usually ~/.bashrc or ~/.zshrc):

sh
eval "$(zoxide init zsh)"   # For zsh

For PowerShell, add this to the end of your config file:

ps1
Invoke-Expression (& { (zoxide init powershell | Out-String) })

Essential Commands

Same as how you use the cd command:

  • z ..: 返回上一级
  • z: 返回家目录
  • z -: 返回上一次进入的目录

See zoxide --help

  • Go to the highest-ranked directory that contains "foo" in the name: zoxide query foo

  • Go to the highest-ranked directory that contains "foo" and then "bar": zoxide query foo bar

  • Start an interactive directory search (requires fzf): zoxide query --interactive

  • Add a directory or increment its rank: zoxide add path/to/directory

  • Remove a directory from zoxide's database interactively: zoxide remove path/to/directory --interactive

  • Generate shell configuration for command aliases (z, za, zi, zq, zr): zoxide init bash|fish|zsh

    CommandDescriptionExample
    z <query>Jump to directoryz docu → goes to ~/Documents
    ziInteractive searchzi → fuzzy find directories

    Other commands such as za, zq, zr do not work. zsh: command not found: za

Database Location

OSPathExample
Windows%LOCALAPPDATA%C:\Users\Alice\AppData\Local\zoxide\db.zo

改造命令

When calling zoxide init, the following flags are available:

  • --cmd
    • Changes the prefix of the z and zi commands.
    • --cmd j would change the commands to (j, ji).
    • --cmd cd would replace the cd command.

如果习惯了使用 cd 命令,可以使用以下改造方法,显式仍然使用 cd 命令,但是背地却是调用了 z 命令。

Add this to the end of your shell config file (usually ~/.bashrc or ~/.zshrc):

sh
eval "$(zoxide init --cmd cd zsh)"   # For zsh

For PowerShell, add this to the end of your config file:

ps1
Invoke-Expression (& { (zoxide init --cmd cd powershell | Out-String) })
最近更新