Last updated on September 7, 2020 by Adrien Brochard
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.
autojump
on LinuxTo install autojump
on Ubuntu or Debian:
$ sudo apt-get install autojump
To install autojump
on CentOS or Fedora, use yum
command. On CentOS, you need to enable EPEL repository first.
$ sudo yum install autojump
To install autojump
on Arch Linux:
$ sudo pacman -S autojump
If you cannot find a package for your distribution, you can always compile from the sources.
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:
$ autojump [name or partial name of the directory]
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.
$ autojump do
If you hate typing too, I recommend making an alias for autojump
or using the default one.
$ j [name or partial name of the directory]
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:
$ autojump d
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:
$ autojump -a [directory]
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
$ autojump -i [weight]
This will result in this directory being more likely to be selected to jump to. The opposite would be to decrease its weight with:
$ autojump -d [weight]
To keep track of all these changes, typing:
$ autojump -s
will display the statistics in the database, while:
$ autojump --purge
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 SSH to 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.
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean