TranslateProject/sources/tech/20190409 UP Shell Script - Quickly Navigate To A Specific Parent Directory In Linux.md
darksun af99c87e6c 选题: 20190409 UP Shell Script – Quickly Navigate To A Specific Parent Directory In Linux
sources/tech/20190409 UP Shell Script - Quickly Navigate To A Specific Parent Directory In Linux.md
2019-04-09 11:49:03 +08:00

5.1 KiB
Raw Blame History

UP Shell Script Quickly Navigate To A 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 but has 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. I mean to say that number of times youd have to go back.

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

It support tab completion so, its become 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 its support zsh and fish shell as well.

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

How To Install up Linux?

Its not based on the distribution and you have to install it based on your shell.

Simple 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 to take the changes to effect.

$ source ~/.bashrc

Simple 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 to take the changes to 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 This In Linux?

We have successfully installed and configured the up script on system. Its time to test it.

Im 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? Quickly go back to one directory. Im currently in /usr/share/icons/Adwaita/256x256/apps and if i want 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? Quickly go back to multiple directory. Im currently in /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 up by full name? Quickly go back to the given directory instead of number.

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

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

How to up by partial name? Quickly go back to the given directory instead of number.

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 allows 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.


via: https://www.2daygeek.com/up-shell-script-quickly-go-back-to-a-specific-parent-directory-in-linux/

作者:Magesh Maruthamuthu 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出