LinuxCommandLibrary

z

Uncompress and execute compressed files

TLDR

Go to a directory that contains "foo" in the name

$ z [foo]
copy

Go to a directory that contains "foo" and then "bar"
$ z [foo] [bar]
copy

Go to the highest-ranked directory matching "foo"
$ z -r [foo]
copy

Go to the most recently accessed directory matching "foo"
$ z -t [foo]
copy

List all directories in z's database matching "foo"
$ z -l [foo]
copy

Remove the current directory from z's database
$ z -x
copy

Restrict matches to subdirectories of the current directory
$ z -c [foo]
copy

SYNOPSIS

z [options] [keywords...]

PARAMETERS

keywords...
    One or more space-separated keywords. z will attempt to find the best matching directory based on these keywords and its frecency database.

-l, --list
    List all matched directories without changing the current working directory. The directories are ordered by frecency.

-r, --rank
    List all directories in the database, sorted by frecency (highest frecency first).

-t, --recent
    List all directories in the database, sorted by recency (most recently visited first).

-x, --exclude
    Exclude the current directory from being recorded in the database. Useful for temporary or sensitive directories.

-c, --cd
    Forces z to perform a cd operation even if it's typically aliased to another function (e.g., in some shell setups).

-e, --edit
    Opens the z database file in your default editor (specified by $EDITOR). Allows manual editing of directory frecency scores.

-h, --help
    Display a brief help message and exit.

-v, --version
    Display version information and exit.

DESCRIPTION

z is a popular command-line utility designed to make navigating frequently visited directories incredibly fast and efficient. Unlike traditional cd which requires precise paths, z learns your habits by keeping track of the directories you visit and how often you visit them. It then uses a "frecency" algorithm (a combination of frequency and recency) to rank these directories.

When you type z followed by a keyword, it attempts to find the best matching directory from its database and instantly changes your current working directory to it. This fuzzy matching capability saves significant time, especially for deeply nested or long directory names. It integrates seamlessly with your shell (Bash, Zsh, Fish) and is particularly useful for developers, system administrators, and anyone who frequently jumps between projects or system locations.

CAVEATS

z is not a standard Linux command; it needs to be installed as a third-party utility. Its functionality relies on a database file, typically ~/.z, which stores your directory visit history. If this file is corrupted or lost, z will lose its learned history. Performance might degrade slightly with an extremely large database, and fuzzy matching can occasionally lead to unexpected directory jumps if keywords are too generic.

INSTALLATION AND INTEGRATION

z is typically installed by cloning its Git repository and then sourcing the z.sh script in your shell's configuration file (e.g., ~/.bashrc, ~/.zshrc). This integration ensures that every cd command is recorded by z.

Example:
git clone https://github.com/rupa/z.git ~/z
echo '. ~/z/z.sh' >> ~/.bashrc

FRECENCY CALCULATION

The 'frecency' score for a directory is a weighted combination of its frequency (how many times it's been visited) and its recency (how recently it was visited). z gives more weight to recent visits, making directories you've accessed recently rank higher, while also factoring in overall visit count. This dynamic scoring helps z adapt to your evolving navigation habits.

HISTORY

The z command was created by rupa and first released around 2011. It was inspired by existing directory jump tools like autojump but aimed for a simpler, more lightweight implementation, focusing purely on the "frecency" algorithm. Written as a shell script, its portability and minimal overhead quickly led to its widespread adoption within the command-line user community as an efficient alternative to traditional directory navigation.

SEE ALSO

cd(1), fasd(1), autojump(1)

Copied to clipboard