Can I shorten the typing needed to `cd` into some well know directories

Here is the way to deal with complex paths to cd frequently.

mkdir ~/Links
ln -s /complexpath/there ~/Links

this will create the symbolic link

~/Links/there

To use this new Links directory efficiently, if your login shell is bash just include this command in your ~/.profile (which is used by all Bourne style shells bash, ksh, zsh…):

CDPATH=~/Links:.
export CDPATH

This means that for every cd, your shell will look within 2 directories to find a localpathname:

~/Links
.

You won't need to restart you session to test it, just run:

. ~/.profile

which means just read my ~/.profile. (You won't have to put it in your ~/.bashrc since there is no need to repeat the same variable initialization when you don't change it.)

Once you have tested it, you will be able to restart your session ;).

From now on, everytime you will want to go to there you will have to type:

cd there

Defining an alias is a very easy way to have a short abbreviation for a longer command. Once you have your aliases right, you could create a section in your .bashrc file (or other startup file) so that you don't have to re-type these aliases for each new shell you start:

in .bashrc:

alias ws4='ssh qsv-rhws4'
alias httpdlog='cd /var/log/httpd/'
alias EC2='ssh -i BMTestEC2.pem [email protected]'

etc.

Log out and back in (or just run . ~/.bashrc) and now you can just type httpdlog and it performs the cd. Or ws4 and it actually performs the ssh command etc.

This removes the need to create (a large amount of) empty links that will cause your home directory too look like a mess.


Try using either autojump or z.

After installing either of the two, you just cd around like normal and they learn your most visited directories and allows you to go to them by only typing a part of the path:

$ cd /very/long/path/foobar
$ cd
$ z foobar
$ echo $PWD
/very/long/path/foobar

I prefer z of the two.