Advanced command-line navigation
Command Line – Navigation

© Lead Image © artqu, 123rf.com
For decades, cd has been a Linux workhorse, but modern drives sometimes call for more efficient navigation tools. Read on for alternatives for advanced command-line navigation.
Change directory (cd
) is one of the first commands that Linux users discover at the command line. It is so basic that it has only a few options. An example of the Unix philosophy that a command should do one thing and do it well, cd
has survived for decades with no change of which I am aware. Still, it was designed for a simpler time, when storage was scarce. On modern drives, it can involve a lot of typing of paths, especially if your directory structure is more than one level deep.
So what are the alternatives? The answers are surprisingly numerous, ranging from those built into the shell, to more recent options that may require extra setup.
Built-In Alternatives
The shell has several ways to make navigation more efficient:
cd
's own shortcuts: Typingcd ..
moves you to the current directory's parent directory. A tilde (~
) moves you to your home directory and a hyphen (-
) to the previous directory (Figure 1).
- The print working directory (
pwd
) command can be used to change elements of the directory name using the structure cd ${PWD/OLD/NEW}.This structure is mostly useful for changing between directories in the same level of the directory hierarchy. It can also be effective in scripting (Figure 2).
- The Bash history can be navigated with arrow keys or by specifying the number of an item in the history with
!NUMBER
. If you have recently switched to a directory, this may be an alternative. - Pressing the Tab key produces possible completions. Eventually as you type, fewer completions are left until only one remains, and it is automatically entered.
- Symbolic links can have a shorter name than their original reference. Creating a series of symbolic links as children of your home directory creates a do-it-yourself navigation structure with minimal typing.
While these built-in alternatives improve on cd
's efficiency, the alternatives listed below have more functionality and are often more efficient. For some, these alternatives' main shortcoming is that they require some configuration to be useful.
autojump
autojump
[1] records the directories you switch to using cd
and creates a database of shortcuts. It requires a somewhat complicated setup. In Fedora and related distributions, you will need to enable the Extra Packages for Enterprise Linux (EPEL) repository that includes autojump
[2]. Most distributions enable autojump
upon installation, but before using Debian and its derivatives you must run the following command:
source /usr/share/autojump/autojump.sh on startup
To permanently enable autojump
, you can add the same command to ~/.bashrc
so that autojump
is available whenever you open a Bash shell.
Beware: If you are using the Zsh shell in any distribution, you will need to find the Zsh version of autojump
. Without this addition, autojump
will not work in Debian. You also have the option of installing from source by cloning from a user account with the command
git clone git://github.com/joelthelion/autojump.git
and then changing the permissions on the file install.py
and running it as root.
Once autojump
is set up, it gradually adds directories to its database (~/.local/share/autojump/
) as you navigate the command line. Alternatively, you can add directories manually with the option --add DIRECTORY
(-a
). Either way, when a directory is added to autojump
, you can switch to it using either the command autojump
or simply j
. Since you only have to type the directory name and not the complete path, you can save keystrokes, especially if you have a deep directory structure. For instance, instead of typing
cd /home/bb/work/journalism/2020/August
I could type simply
j August
Should you choose, you can also open a directory in the default file manager of your desktop environment using the command jo DIRECTORY
. If a directory is not a top-level one, then the command is jc DIRECTORY
. Depending on the speed of your machine, the desktop file manager may take a few seconds to open. You can also use --complete
to enable tab completion in your current session.
You can view the database with the option --stat
(Figure 3). You will notice that directories are weighted according to how many times you switch to them. You can use the options --increase WEIGHT DIRECTORY
(-i
) and --decrease WEIGHT DIRECTORY
(-d
) to help eliminate any confusion between similarly named directories and --purge
to remove paths that have been removed. Looking at the autojump_errors
file can help you detect duplicate path names.

autojump
is unable to work with files that start with a hyphen. Otherwise, after it is set up, autojump
is a powerful navigation tool.
cdargs
cdargs
[3] is similar to autojump
, except that its documentation refers to directory bookmarks. Similarly to autojump
, cdargs
installs by evoking one of the scripts provided in its package, either in the current session with the command
source /usr/share/doc/cdargs/examples/cdargs-bash.sh
or permanently by adding the same command to your bash.rc
file.
You can build a navigation system by changing to a directory and running the command ca
, which will create a bookmark with the same name as the directory, or ca BOOKMARK
, which can provide a shorter name. Alternatively, you can run cv
and use a
to add the current directory by its full name, d
to delete the highlighted directory, and e
to edit the list in your default text editor. You can close any list window with q
.
To use cdargs
to navigate, use the command cdb BOOKMARK
. If you do not specify a directory, cdb
opens a list of directories from which to choose. You can also enter cdb Lc
to select by highlighting an entry on a list of directories and pressing the Enter key (Figure 4).
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
Find SysAdmin Jobs
News
-
LibreOffice 7.5 has Arrived and is Loaded with New Features and Improvements
The favorite office suite of the Linux community has a new release that includes some visual refreshing and new features across all modules.
-
The Next Major Release of Elementary OS Has Arrived
It's been over a year since the developers of elementary OS released version 6.1 (Jólnir) but they've finally made their latest release (Horus) available with a renewed focus on the user.
-
KDE Plasma 5.27 Beta Is Ready for Testing
The latest beta iteration of the KDE Plasma desktop is now available and includes some important additions and fixes.
-
Netrunner OS 23 Is Now Available
The latest version of this Linux distribution is now based on Debian Bullseye and is ready for installation and finally hits the KDE 5.20 branch of the desktop.
-
New Linux Distribution Built for Gamers
With a Gnome desktop that offers different layouts and a custom kernel, PikaOS is a great option for gamers of all types.
-
System76 Beefs Up Popular Pangolin Laptop
The darling of open-source-powered laptops and desktops will soon drop a new AMD Ryzen 7-powered version of their popular Pangolin laptop.
-
Nobara Project Is a Modified Version of Fedora with User-Friendly Fixes
If you're looking for a version of Fedora that includes third-party and proprietary packages, look no further than the Nobara Project.
-
Gnome 44 Now Has a Release Date
Gnome 44 will be officially released on March 22, 2023.
-
Nitrux 2.6 Available with Kernel 6.1 and a Major Change
The developers of Nitrux have officially released version 2.6 of their Linux distribution with plenty of new features to excite users.
-
Vanilla OS Initial Release Is Now Available
A stock GNOME experience with on-demand immutability finally sees its first production release.