UP Shell Script – To Navigate specific parent directory in Linux

Recently we had written an article about bd command, which help us to quickly go back to the specific parent directory.

Even, the up shell script allow us to perform the same with different approach so, we would like to explore it.

This will allow us to quickly navigate to a specific parent directory with mentioning the directory name.

Instead we can give the directory number.

Stop typing cd ../../.. endlessly ,navigate easily to a specific parent directory by using up shell script.

It support tab completion so, it will be more convenient.

The up.sh registers the up function and some completion functions via your .bashrc or .zshrc file.

It was completely written using shell script and it supports zsh and fish shell as well.

We had written an article about autocd. It’s a builtin shell variable that helps us to navigate to inside a directory without cd command.

How to install up Linux?

You have to install it based on your shell and not based on the distribution

Simply run the following command to enable up script on bash shell.

$ curl --create-dirs -o ~/.config/up/up.sh https://raw.githubusercontent.com/shannonmoeller/up/master/up.sh

$ echo 'source ~/.config/up/up.sh' >> ~/.bashrc

Run the following command for the changes to take effect.

$ source ~/.bashrc

Simply run the following command to enable up script on zsh shell.

$ curl --create-dirs -o ~/.config/up/up.sh https://raw.githubusercontent.com/shannonmoeller/up/master/up.sh

$ echo 'source ~/.config/up/up.sh' >> ~/.zshrc

Run the following command for the changes to take effect.

$ source ~/.zshrc

Simple run the following command to enable up script on fish shell.

$ curl --create-dirs -o ~/.config/up/up.fish https://raw.githubusercontent.com/shannonmoeller/up/master/up.fish

$ source ~/.config/up/up.fish

How to use up in Linux?

We have successfully installed and configured the up script on system. Let’s test it.

I’m going to take the below directory path for this testing.

Run the pwd command or dirs command to know your current location.

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ pwd
or
daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ dirs

/usr/share/icons/Adwaita/256x256/apps

How to up one level? and quickly go back to one directory. I’m currently in /usr/share/icons/Adwaita/256x256/apps and if we need to go one directory up 256x256 directory quickly then simple type the following command.

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ up

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256$ pwd
/usr/share/icons/Adwaita/256x256

How to up multiple levels?

/usr/share/icons/Adwaita/256x256/apps and if I want to go to share directory quickly then simple type the following command.

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ up 4

daygeek@Ubuntu18:/usr/share$ pwd
/usr/share

How to use up by full name instead of number.?

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256×256/apps$ up icons

daygeek@Ubuntu18:/usr/share/icons$ pwd

/usr/share/icons

How to up by partial name of the folder?

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ up Ad

daygeek@Ubuntu18:/usr/share/icons/Adwaita$ pwd
/usr/share/icons/Adwaita

As i told in the beginning of the article, it supports tab completion.

daygeek@Ubuntu18:/usr/share/icons/Adwaita/256x256/apps$ up 
256x256/  Adwaita/  icons/    share/    usr/      

This tutorial helps you to quickly go back to a specific parent directory but there is no option to move forward quickly.

We have another solution for this, will come up with new solution shortly. Please stay tune with us.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *