Complementing cd with autojump
Big Jump
Autojump is a mature and widely available command-line tool for navigating your directory structure. We show you how it works.
The Linux directory structure was developed when hard drives were small, and all you needed for navigation was a file manager or a handful of commands like cd
and ls
. Today, however, multiterabyte hard drives make the list of directories longer and deeper and therefore more difficult to navigate. On the desktop, these changes have prompted navigation alternatives like Nepomuk [1] and Zeitgeist [2]. At the command line, they have resulted in several different solutions, the most popular of which is autojump [3].
Autojump apparently takes its name from a means of pre-programming moves in some of the games in The Legend of Zelda series. Like its gaming namesake, autojump is a means of jumping straight to a directory without laboriously following its full path. Autojump maintains a plain-text database of the directories you visit and how often you visit each one and, on the basis of this information, jumps to the closest match according to what you type.
As the project homepage notes, "autojump isn't meant to be a drop-in replacement for cd, but rather a complement. Cd is fine when staying in the same area of the filesystem; autojump is there to help when you need to jump far away from your current location." Autojump is especially useful with the root account, which tends to make longer jumps in the directory structure than most accounts.
Many major distributions, including Debian, Fedora, ArchLinux, Gentoo, Frugalware, and Slackware, carry autojump in their repositories. Versions also exist for OS X and Windows. You can also install autojump by cloning the project's Git repository with the command
https://github.com/joelthelion/autojump
then switching to the download directory and running the script ./install.py
.
Before choosing your installation method, you might want to check how recent your distribution's version is and check its limitations. For example, the man page for v20, the version of autojump in Debian Stable, states that it does not run on the zsh shell, nor in Gnome 3.0 or LXDE. You can keep track of other limitations on the projects Issue page [4].
Training autojump
To activate autojump, enter:
./usr/share/autojump/autojump.sh
Immediately after installation, the database will be empty, and autojump will not be functional. To get it working, you must either visit a few directories using cd, or else add directories manually to the database with
autojump -a DIRECTORY or autojump --add DIRECTORY
As you might expect, the more you use autojump, the more accurate and useful it becomes. You can view the contents of the database (Figure 1) with either of these commands:
autojump --stat jumpstat
In addition to the complete directory path, the autojump database also assigns a key weight to each entry, based on the amount of time you spend in the directory. By default, each entry's weight decays over time – in other words, if you start moving less frequently to a directory, autojump will gradually become less likely to suggest it as a target into which to jump. To prevent such weight decay, you can use the command structure
autojump -a DIRECTORY --completion.
You can also edit ~/.local/share/autojump/autojump.txt
, both to add paths and to adjust weights. These manual edits can be especially useful if you have two directories with similar names, such as ~/scripts
and ~/work/scripts
, but you want to ensure that autojump suggests one in preference to the other. To remove a directory from the database, give it a negative weight and save the file. After all your edits, restart autojump so that it is using the latest figures.
Using autojump
Once the database has enough contents to be useful, start autojump. To jump to a directory, use the command j DIRECTORY
. Type as much of the directory name as you think necessary, and autojump will try to match what you type with its database entries, printing its nearest match in red and switching to its suggestion (Figure 2). If two database entries match your typing, autojump suggests the first in alphabetical order. Autojump has no way of choosing the second until you type more.
Note that all database entries are case-insensitive. If you are regularly moving between directories in a command-line session, you might periodically run the jumpstat
command so that you can see autojump's entries and type the minimum possible to jump. You do not need to type the full path, but remember that autojump only works in the instance of a terminal in which it is started. If you start autojump in one terminal, then open a second tab, it will not be active in the second tab unless you specifically start it in the second tab.
Should the directory contain a space or other illegal character – which can easily happen if the directory is created from the desktop – add the -b
or --bash
option and enclose the name in single or double quotation marks so that autojump will try to match the entire string. Otherwise, autojump will not locate a match, even if the directory is listed in the database without quotation marks.
By default, autojump tries to reduce database entries by treating symbolic links as paths to the original directory. However, if you prefer the slightly quicker results of listing symbolic links separately, add the export AUTOJUMP_KEEP_SYMLINKS=1
line to your ~/.bashrc
file.
Other Jump Tools
Autojump is not the only tool that uses a database for faster navigation. One very similar program is z [5]. It works much like autojump but includes some additional features, such as restricting matches to subdirectories of the present working directory and distinguishing between overall rank or weight and recent access. A similar tool called v [6] is a Vim extension that works with the list of recently opened files.
Another similar tool is FASD [7], which uses capacities similar to autojump or z to find and open files as well as directories. FASD also includes unique aliases and environmental variables to improve its performance.
Both z and FASD have features that would enhance autojump. Some day, either may surpass autojump. However, for now, autojump remains the most mature and widely available jump tool. Unless its interface limitations affect you, autojump is quick to learn and can seriously reduce your typing as you navigate your constantly deepening and lengthening directory structure.
Infos
- Nepomuk: https://en.wikipedia.org/wiki/NEPOMUK_%28framework%29
- Zeitgeist: http://zeitgeist-project.com/
- Autojump: https://github.com/joelthelion/autojump
- Autojump Issues: https://github.com/joelthelion/autojump/issues
- z: https://github.com/rupa/z
- v: https://github.com/rupa/v
- FASD: https://github.com/clvv/fasd
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.