Short-cut for switching to a given directory
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)
There are two options:
If you want to be in a specific directory everyt time you open a bash terminal, edit your
~/.bashrc
file and just add the linecd Directory
, for examplecd ~/Desktop
.If you want to have several short-cuts, you can always use global variables, which you can set in your
~/.bashrc
file as followsexport a=/tmp
and then you would be able to docd $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.
Bash aliases are useful for creating short-cuts to commonly run commands.
In
~/.bashrc
, add a line similar to the following to create the alias:alias jump1='cd /long/path/name/that/is/frequently/used'
Close and open the terminal again, or run
source ~/.bashrc
.From now on, you can just run
jump1
to execute that longcd
command.
See also:
- How can I create an alias for cd and ls?
- How do I create a permanent Bash alias?