Open In App

Autojump – An Advanced ‘cd’ Command to Quickly Navigate Linux Filesystem

The AutoJump is a command-line utility tool that helps us to navigate the file system more efficiently by quickly jumping to recently visited directories. AutoJump keeps a record of directories previously accessed by the user thus we will be able to switch between the directories swiftly instead of the traditional way of traversing it through the hierarchy. This is achieved by keeping track of the directories visited by the user and assigning importance or “weight” to the directories based on factors such as the time spent by the user.

Check out the official GitHub repository of AutoJump here: https://github.com/wting/autojump. This article will guide you through the installation as well as the usage of AutoJump.



Features

Syntax

Autojump can be used using the following command.

autojump [or] j

j is a convenience wrapper function around autojump. Any option that can be used with autojump can be used with j.



Setting up the environment for AutoJump

Approach 1: Installation of AutoJump using the distribution repository.

Step 1: Do a system upgrade as the root user to refresh the repository packages.

$ sudo apt-get update      [APT System]
$ sudo yum update            [YUM System]
$ sudo dnf update              [DNF System]

Step 2: Next, make use of the command that corresponds to your Linux distribution.

$ sudo apt install autojump          [Debian/Ubuntu]
$ sudo packman -S autojump     [Arch]
$ sudo yum install autojump        [Fedora/Cent]

Note: For Debian-based systems you need to perform a manual activation of the script. Run the following command to edit the shell’s configuration file [Default shell is bash].

sudo nano ~/.bashrc

Then add the following line at the end of the file.

. /usr/share/autojump/autojump.sh

Step 3: Verify the installation using the following command.

$ autojump

or

$ j

Verifying installation of AutoJump

Approach 2: Installation of AutoJump using the Source.

Step 1: For installing AutoJump from the source, you need to ensure that Git is already installed. To install git use the following command.

$ sudo apt install git          [Debian/Ubuntu]
$ sudo pacman -S git       [Arch]
$ sudo yum install git        [Fedora/Cent]

Step 2: Clone the repository using the “git clone” command in the home directory or any directory of your choice.

$ git clone https://github.com/wting/autojump.git

Step 3: Navigate to the cloned repository using the following command.

$ cd autojump

Step 4: Execute the following command to run the installation script.

$ chmod 755 install.py
$ ./install.py

Basics of AutoJump

Let us assume we have two directories named “Alan” and “bob”. So if we have to jump to a directory alan, the following command is used.

j alan

You can jump to a sub-directory without typing out the entire directory name using the following command.

jc bob

One can also open the Operating System’s file explorer instead of jumping to the directory.

jo pictures

The same is also applicable for child directories.

jco images

Multiple Arguments

Let us assume the following directories along with their weights.

40   /home/user/mail/inbox
20   /home/user/work/inbox

You can influence the behavior of the “autojump” command by providing multiple arguments. For instance, if you want to prioritize a different entry, such as “work” over “mail,” you can use the command “j w in” instead of just “j in.” With “j w in,” the directory will change to “/home/user/work/inbox,” considering your preference for the “work” directory over the “mail” directory as the higher-weighted choice.

Example

AutoJump becomes operational only after you’ve visited a directory; in other words, you need to visit a directory at least once before jumping to it. Let us create some sample directories and visit them before testing AutoJump. You can either use “autojump” or “j” to use AutoJump, “j” is a convenience wrapper function around autojump. Any option that can be used with “autojump” can be used with “j” and vice versa.

$ mkdir -p geek/for/
$ mkdir -p g/f/g/
$ cd geek/for/
$ cd ~
$ cd g/f/
$ cd ~

To check the weights of the visited directories use the following command.

$ j -s

To jump to a directory use the following command.

$ j <directory-name>

To jump to a child directory that is within, use the following command.

$ jc

Use the following command to jump to the directory and as well as open it in the file explorer.

jco geek/

To learn more about AutoJump and the available commands use the below command.

autojump --help

If u delete any directory, the weights will remain in the Autojump records. So once you remove any directory it must be purged from the log file. To do this execute the following command.

$ j --purge

Setting weight to the directories

You can increase or decrease the weight of a directory using the “-i” and the “-d” flag. This will alter the priority of the directories cause the weights directly affect the priority of the directories.

j -i [WEIGHT]
j -d [WEIGHT]

Advantages of AutoJump

Disadvantages of AutoJump

Conclusion

Thus we installed and configured AutoJump a command line tool which helps us to swiftly navigate through directories and remember our most frequented locations, it has simplified the way we interact with the command line. Furthermore AutoJump’s cross-platform compatibility ensures that users on various operating systems can utilize the benefits of the tool.


Article Tags :