How to define a symbolic link that I can use in every directory

Most shells have a CDPATH variable that cd can lookup for directories to change to in the same way that executables are searched in $PATH.

So if you add your symlinks in a ~/projects directory and do CDPATH=~/projects, you'll be able to do cd foo to go in ~/projects/foo

With zsh, if $var contains a path you can do cd ~var to cd to that path. The useful part of that is when your prompt has %~ which then reflects it in your prompt:

$ proj1=/usr/local proj2=/etc/apache2
$ PS1='%~$ '
$ cd ~proj1
~proj1$ cd ~proj2/sites-enabled
~proj2/sites-enabled$

With setopt cdablevars, you can also do cd proj1 instead of cd ~proj1.


You probably want to use variables instead of symbolic links, e.g.

export project=/home/me/project

then

cd $project

or

vim $project/file

UPDATE

As pointed out by peterph, you can also combine these (including predefined variables), e.g.

export project=$HOME/project

Tags:

Bash

Symlink