As useful as navigating through directories from the command line is, rarely anything has become as frustrating as repeating over and over "cd ls cd ls cd ls ..." If you are not a hundred percent sure of the name of the directory you want to go to next, you have to use ls. Then use cd to go where you want to. Hopefully, a lot of terminals and shell languages now propose a powerful auto-completion feature to cope with that problem. But it remains that you have to hit the tabulation key frenetically all the time. If you are as lazy as I am, you will be very interested in autojump. autojump is a command line utility that allows you to jump straight to your favorite directory, regardless of where you currently are.
Install autojump on Linux
To install autojump on Ubuntu or Debian:
To install autojump on CentOS or Fedora, use yum command. On CentOS, you need to enable EPEL repository first.
To install autojump on Archlinux:
If you cannot find a package for your distribution, you can always compile from the sources on GitHub.
Basic Usage of autojump
The way autojump works is simple: it records your current location every time you launch a command, and adds it in its database. That way, some directories will be added more than others, typically your most important ones, and their "weight" will then be greater.
From there you can jump straight to them using the syntax:
Notice that you do not need a full name as autojump will go through its database and return its most probable result.
For example, assume that we are working in a directory structure such as the following.
Then the command below will take you straight to /root/home/doc regardless of where you were.
If you hate typing too, I recommend making an alias for autojump or using the default one.
Another notable feature is that autojump supports both zsh shell and auto-completion. If you are not sure of where you are about to jump, just hit the tabulation key and you will see the full path.
So keeping the same example, typing:
and then hitting tab will return either /root/home/doc or /root/home/ddl.
Finally for the advanced user, you can access the directory database and modify its content. It then becomes possible to manually add a directory to it via:
If you suddenly want to make it your favorite and most frequently used folder, you can artificially increase its weight by launching from within it the command
This will result in this directory being more likely to be selected to jump to. The opposite would be to decrease its weight with:
To keep track of all these changes, typing:
will display the statistics in the database, while:
will remove from the database any directory that does not exist anymore.
To conclude, autojump will be appreciated by all the command line power users. Whether you are ssh-ing into a server, or just like to do things the old fashion way, reducing your navigation time with fewer keystrokes is always a plus. If you are really into that kind of utilities, you should definitely look into Fasd too, which deserves a post in itself.
What do you think of autojump? Do you use it regularly? Let us know in the comments.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Adrien Brochard (see all)
- What are the best plugins to increase productivity on Emacs - December 24, 2015
- What is a good IDE for R on Linux - October 11, 2015
- How to automatically dim your screen on Linux - September 1, 2015