Home Command line utilities Create Shortcuts To The Frequently Used Directories In Linux

Create Shortcuts To The Frequently Used Directories In Linux

By sk
Published: Last Updated on 4.1K views

A while ago, we learned about pushd, popd and dirs commands, which are used for CLI faster navigation. These three commands provides a way faster navigation between directories. Today, I stumbled upon a similar tool called "shortcut" that can also be used for faster and easier navigation between a stack of directories. You can use this tiny tool for making shortcuts to your most commonly and frequently used directories in your SHELL. It is known to work on ZSH and BASH shells.

Install Shortcut in Linux

To install shortcut, git clone its repository:

$ git clone https://github.com/zakkor/shortcut.git

The above command will clone the contents in a folder called "shortcut" in your current working directory.

Go to the "shortcut" directory:

$ cd shortcut/

Run the following command to install it:

$ sh install.sh

The above command will put an executable shortcut in /usr/local/bin, and append a shell function called sc to your .zshrc.

If you use BASH, edit install.sh file:

$ vi install.sh

Change the following line:

cat alias.sh >> ~/.zshrc


cat alias.sh >> ~/.bashrc

Save and close the file. Then, run the following command to install "shortcut":

$ sh install.sh

Finally, run the following command to update the changes.

$ source ~/.bashrc

Create Shortcuts To The Frequently Used Directories In Your Shell Using Shortcut

Let us create a sample directory hierarchy.

$ mkdir -p abcd/efgh/ijkl/mnop/qrst/uvwx/yz/

Here is our directory hierarchy:

$ tree abcd/
└── efgh
 └── ijkl
 └── mnop
 └── qrst
 └── uvwx
 └── yz

6 directories, 0 files

Assume we are in abcd/efgh/ijkl/mnop/qrst/uvwx/yz/ directory.

To create a shortcut to this directory, just run:

$ sc yz .

Shortcut command in action

Please mind the dot (.) at the end of the command. Here, yz is the shortcut name to abcd/efgh/ijkl/mnop/qrst/uvwx/yz/ directory. You can use any name to the shortcut. In this case, I have used the actual name of directory (yz) as its shortcut name.

From now on, you can cd to /yz directory from any location by just using the following command:

$ sc yz

Shortcut command in action

As you see in the above screenshot, it is a long path and will take many keystrokes to navigate to this directory. Usually, we use the following command to go to this directory.

$ cd abcd/efgh/ijkl/mnop/qrst/uvwx/yz/

But, you don't have to type the full path. Just create a shortcut to /some/long/path/ directory using "shortcut" utility and cd to that directory in no time.

You can also create a shortcut using the absolute path if you want, like below:

$ sc go abcd/efgh/ijkl/mnop/qrst/uvwx/

Here, go is the shortcut name to the directory abcd/efgh/ijkl/mnop/qrst/uvwx/.

To go to that directory, just type:

$ sc go

Shortcut command in action

All shortcuts will be stored one by one in a file called ~/.scrc as shown below.

yz /home/sk/abcd/efgh/ijkl/mnop/qrst/uvwx/yz
go /home/sk/abcd/efgh/ijkl/mnop/qrst/uvwx

All shortcuts are persistent. If you don't want a shortcut to specific directory, just open this file in any editor and delete the respective shortcut line.

Of course, you can use alias or ln for navigating stack of directories. However, It's always nice to know of the alternative. For those looking for an alternative approach, give it a try. You won't be disappointed!


You May Also Like


Rod March 16, 2022 - 7:44 pm


roy July 22, 2023 - 4:20 pm

Works great, feature request: shortcut name autocomplete on tab press.


Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More