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
Direct Download
Read full article as PDF:
Price $2.95
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
News
-
An All-Snap Version of Ubuntu is In The Works
Along with the standard deb version of the open-source operating system, Canonical will release an-all snap version.
-
Mageia 9 Beta 2 Ready for Testing
The latest beta of the popular Mageia distribution now includes the latest kernel and plenty of updated applications.
-
KDE Plasma 6 Looks to Bring Basic HDR Support
The KWin piece of KDE Plasma now has HDR support and color management geared for the 6.0 release.
-
Bodhi Linux 7.0 Beta Ready for Testing
The latest iteration of the Bohdi Linux distribution is now available for those who want to experience what's in store and for testing purposes.
-
Changes Coming to Ubuntu PPA Usage
The way you manage Personal Package Archives will be changing with the release of Ubuntu 23.10.
-
AlmaLinux 9.2 Now Available for Download
AlmaLinux has been released and provides a free alternative to upstream Red Hat Enterprise Linux.
-
An Immutable Version of Fedora Is Under Consideration
For anyone who's a fan of using immutable versions of Linux, the Fedora team is currently considering adding a new spin called Fedora Onyx.
-
New Release of Br OS Includes ChatGPT Integration
Br OS 23.04 is now available and is geared specifically toward web content creation.
-
Command-Line Only Peropesis 2.1 Available Now
The latest iteration of Peropesis has been released with plenty of updates and introduces new software development tools.
-
TUXEDO Computers Announces InfinityBook Pro 14
With the new generation of their popular InfinityBook Pro 14, TUXEDO upgrades its ultra-mobile, powerful business laptop with some impressive specs.