Open In App

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

Last Updated : 02 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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

  • AutoJump is an open-source software and is available for modification.
  • Provides high customizability with the help of configuration files.
  • AutoJump is available for multiple platforms such as Windows, Linux, and MacOS.
  • Assign weight to the directories based on the usage patterns.
  • Is compatible with various shell environments.
  • Provides efficient directory navigation.

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]

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

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]

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

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

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

Step 3: Verify the installation using the following command.

$ autojump

or

$ j

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

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

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

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

jc bob

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

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

jo pictures

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

g6

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.

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

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

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 ~

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

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

$ j -s

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

To jump to a directory use the following command.

$ j <directory-name>

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

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

$ jc

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

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

jco geek/

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

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

autojump --help

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

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

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

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]

g10

Advantages of AutoJump

  • Seamless Directory Navigation: It saves time and reduces the need to remember and type out long directory paths.
  • Cross-Platform: Autojump is available on various Unix-like operating systems, including Linux and macOS.
  • Compatibility: Is compatible with various shell environments.
  • Highly Customizable: Provides high customizability with the help of configuration files.
  • Learning Behavior: Autojump learns and adapts to your navigation patterns.

Disadvantages of AutoJump

  • Limited first class support: First class support is only available for bash and zsh, the rest of the shells are completely dependent on the community.
  • Inconsistency in Weights: It might not predict your intent accurately, leading to unexpected results.
  • Disk Consumption: The maintaining of directory history may consume disk space overtime.

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.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads