Jump! Quick directory change at the command line
Jump! Quick directory change at the command line
Bd, autojump, and Fasd improve the workflow for command-line aficionados thanks to quick navigation in the filesystem.
With a little practice, working at the command line lets you feel the true power of Linux. However, the standard tools are not always as convenient as they are powerful, or as the user would hope.
If you frequently work at the command line, you most likely use the cd
"change directory" command on a daily basis. In this article, I introduce a few helpers that promise greater convenience and speed, especially when changing directories in deeply nested paths. Bd, autojump, and Fasd are available as tools for different shells.
Inconvenient
The various Linux shells already provide some help with improved navigation in the command-line directory jungle, starting with finding out where you are. The pwd
command helps by outputting your working directory's path. If you now want to jump up one or more levels, you can usually do this with:
cd ..
The two periods mean one step up in the direction of the root. You can jump up two steps by using:
cd ../..
However, frequent directory changes involve much typing, which can lead to errors. If you have to switch often between two directories in different places in the directory tree, the cd -
command helps by taking you to the last directory you visited.
The directory stack provides further assistance: Multiple directories can be piled onto a stack. Bash provides the pushd
, popd
, and dirs
commands to navigate in this stack [1]. If you replace cd
with pushd
for the directory change, the shell always places the directory to enter at the top of a stack. It remembers the stack – so you don't need to – and displays it after the command. Using popd
, you can work your way back up the stack.
For orientation, the dirs -l -v
command displays the entire stack. To create the stack, you first have to access the directories with pushd
to add them to the stack, which proves useful if you have to switch between a few directories in a working session: The tool consecutively numbers the stack, and you can jump to the folders with the use of these numbers.
However, bd, autojump, and Fasd offer a more convenient approach; all the major distributions have them in their repositories. The whohas
command, installed via your package manager, tells you where to find them. Typing whohas autojump
gives you a list of distributions with the package, including the version and the respective branch.
You also can set up the bd [2] script for many distributions via a package manager. After installing, enter the two commands from Listing 1 to facilitate running bd. If bd is not available in the Linux derivative that you use, install it manually following notes from the project site on GitHub.
Listing 1
Running bd
Shorter Return Path
Imagine that you have used cd
to enter the /home/fritz/foo/bar/bat/test/bd/
directory and now want to go back to /home/fritz/foo/bar/
. You would usually enter:
cd ../../../
With the bd script you just installed, bd bar
would do the trick: bd supports autocompletion, so you do not have to type out the directory names; usually you just need two or three letters.
Bd only operates backward, not forward. But it can also be used with other commands, for example: ls
, du
, zip
, and tar
. The command
ls -l `bd ba`
lists the content of the /bar
directory, even though you are still in /bd
. The call
du -cs `bd fr`
displays the size of /fritz
(Figure 1).
autojump
Autojump [3] makes use of the basics of the directory stack described above and further expands on them. It also facilitates navigation in the directory tree in both directions, unlike bd. Autojump can be used under Linux, Mac OS, and Windows with the Bash (from version 4.0), Zsh, and fish shells and experimentally with the tcsh and Clink shells.
Most distributions offer autojump packages. Under Debian and its subsidiaries; you can add the tool to the system using the command from Listing 2. Autojump works with a database that you initially have to fill by working with cd
for a while. Alternatively, you can target folders that you use often.
Listing 2
Installing autojump
You will find the database under ~/.local/share/autojump/autojump.txt
. You can query the contents of the database at any time using j --stat
. The j --purge
call removes directories that no longer exist from the database.
If you also want to test Fasd [4], the final helper discussed in this article, it makes sense to install it now, because it also benefits from the actions for filling the database. To do this, type the entries from Listing 3 after the install.
Listing 3
Installing Fasd
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.