简体   繁体   中英

Ubuntu how to create a shortcut that execute a command

When I work I often do:

cd ~/dev/lab/prod/

It is just an example but I would like to be able just to run:

prod

With the same effect (changing into the ~/dev/lab/prod folder).

Alias is what you are looking for.

For bash you have to do following steps:

1) Open your .bashrc

nano ~/.bashrc

2) Add new alias (at the end of file)

alias prod='cd ~/dev/lab/prod/'

3) Save and close the file

4) Source the .bashrc file

source ~/.bashrc

5) Use created alias prod for cd ~/dev/lab/prod/ command

  1. Open a text editor
  2. Name the file prod.sh
  3. Add the following line:

     cd ~/dev/lab/prod 
  4. Make the file script executable:

     chmod +x prod.sh 
  5. Run the file

     ./prod.sh 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM