Short-cut for switching to a given directory

In the Ubuntu terminal I find myself spending considerable time to switch to a particular directory every time the computer starts up. Is there some way I can make this process easier? Is there some hotkey or some quick directory change that I can use (like speed dial on a phone)?

 eg:
    cd 1:Changes to saved directory one

Solution 1:

Also have a look at autojump, it builds a database with previously visited directories and then you can jump to it. So for instance you have

/home/user/this/long/and/annoyingly/deep/directory/workstuff

then if you have visited it once you can jump to it by

j workstuff

or even

j stuff

because it also works with partial matches. If more than one directory matches you jump to the one that is most visited, if this is not the one you wanted, then repeat the command to go to the second.

However it gets better! If you also have the directory

/home/user/stuff

and you do

j stuff 

and then TabTabTab you get (in the order of most visited)

$ j stuff__
stuff__1__/home/user/this/long/and/annoyingly/deep/directory/workstuff
stuff__2__/home/user/stuff

and then you can just press the number of the directory you want!

To install you can just use sudo apt-get install autojump and then you need to add

source /usr/share/autojump/autojump.bash

to your ~/.bashrc.

More information here: https://github.com/wting/autojump (also instruction on how to install this from src which gets you the most recent version)

Solution 2:

There are two options:

  1. If you want to be in a specific directory everyt time you open a bash terminal, edit your ~/.bashrc file and just add the line cd Directory, for example cd ~/Desktop.

  2. If you want to have several short-cuts, you can always use global variables, which you can set in your ~/.bashrc file as follows export a=/tmp and then you would be able to do cd $a which would bring you to /tmp.

Remember that after editing your .bashrc file you have to restart the terminal or open a new one.