Autojump: An Advanced Way to Navigate Long Path Directories in Linux

Do you ever get tired of navigating directories back and forth? I am 100% sure that the answer will be yes, and at that point, you will launch multiple windows and operate them all at once.

What if I told you that you could have a single window and dynamically navigate through multiple directories without specifying the full path? Yes, it’s true, and you achieve this by using autojump in Linux.

What is Autojump in Linux?

Autojump is a Linux command line program that helps you easily navigate directories back and forth with long paths by just specifying the directory name.

How is this possible? The mechanism is very easy to understand. When you load autojump in your shell, it will store all your inputs with the cd command in its own database.

In the future, when you specify the directory name using the autojump command, it will directly navigate you through the directory without specifying the full path.

How do I Install Autojump on Linux?

The good news is, autojump is available in major Linux distribution repositories, including macOS. Execute any of the below commands depending upon your distribution type to install autojump on Linux.

$ sudo apt install autojump               #For Ubuntu, Debian, Linux Mint, Pop!_OS
$ sudo dnf install autojump               #For RHEL, Fedora, AlmaLinux, CentOS
$ yay -Sy autojump                        #For Arch, Manjaro, EndeavourOS

Homebrew is the recommended installation method for macOS:

$ brew install autojump

In addition to the distribution package manager, you can install it as a plugin if you are using zsh or fish shell. Install autojump-zsh for zsh, autojump-fish for fish, etc.

How to Configure Autojump on Linux?

Autojump will not work unless you activate it in your shell. There are two ways to activate it: temporary and permanent.

Temporary changes will only be effective until the current session is closed. While the permanent will work even after the new terminal session is started. Both methods are shown below.

Autojump temporarily loads in your shell

$ source /usr/share/autojump/autojump.sh

Autojump permanently loads into your shell

$ echo "source /usr/share/autojump/autojump.sh" >> ~/.bashrc

How to Check Whether Autojump is Working on Linux?

Once the installation and configuration part is done, you can verify the version of the Autojump by using the autojump or j commands, as shown below.

$ autojump -v
OR
$ j -v

Below is the output of the above command.

Check Autojump Version
Check Autojump Version

Note: Both commands are similar and can be used in the opposite order. However, it’s interesting to know that the j command is a wrapper around Autojump.

How to Use Autojump on Linux?

For demonstration purposes, I’ll first navigate through some directories including the system and manually created by me, as shown below.

Also Read: Walk: A Lightweight Terminal Navigator

Navigating through directories
Navigating through directories

As you navigate through directories from their full paths, autojump will record the full paths in its database for future use. It will make it easy for you to navigate back and forth in the directory without needing a full path.

#Example One

Let’s go back to the /var/ww/html path without specifying the full path using the following command.

$ j html

Below is the output of the above command.

Navigating a previously visited path
Navigating a previously visited path

#Example Two

Jumping to the child directory (sub-directory of the current directory) of ~/parentdir/ path.

$ jc parentdir

Below is the output of the above command.

Jumping to the child directory
Jumping to the child directory

#Example Three

Instead of jumping to a directory, you can open the path in the distribution file manager like Nautilius for GNOME.

$ jo html

Below is the output of the above command.

Open the Directory That Contains html
Open the Directory That Contains HTML

#Example Four

To open a child directory in the file manager.

$ jco parentdir

Below is the output of the above command.

Open the Child Directory
Open the Child Directory

Where is the Autojump Database?

You can execute the below command to view the database entries and their key weights stored in the Autojump database.

$ j --stat

Below is the output of the above command.

View the database entries and their key weights
View the database entries and their key weights

However, you can directly navigate to the ~/.local/share/autojump/ configuration path from where all the input records and error logs are stored.

Autojump configuration directory
Autojump configuration directory

Note: Do not modify the configuration file, otherwise you might lose all of your database entries.

Known Issues

For bash users, autojump keeps track of directories by modifying $PROMPT_COMMAND. Do not overwrite $PROMPT_COMMAND:

export PROMPT_COMMAND="history -a"

Instead, append this to the end of the existing $PROMPT_COMMAND:

export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ;} history -a"

For any questions, open a GitHub issue:

Leave a Reply