1

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

gorn
  • 5,042
  • 7
  • 31
  • 46
PierreD
  • 860
  • 1
  • 14
  • 30
  • 1
    Possible duplicate of [How to pass command line arguments to a shell alias?](https://stackoverflow.com/questions/941338/how-to-pass-command-line-arguments-to-a-shell-alias) – leopal Dec 04 '18 at 14:46

2 Answers2

5

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

Vladas Maier
  • 2,054
  • 2
  • 22
  • 34
-1
  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
    
  • 1
    This is broken, and a common FAQ: https://stackoverflow.com/questions/255414/why-doesnt-cd-work-in-a-shell-script – tripleee Dec 04 '18 at 15:52