Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to write a symbolic link such that no matter where am I on the file system, I can use for example project to point the directory home/me/project? I would like to use commands like cd project, nano project/file1.tex and so on. Do I have to write a symbolic link to all of my directories?

share|improve this question

2 Answers 2

up vote 15 down vote accepted

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.

share|improve this answer

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
share|improve this answer
1  
Or even better project=$HOME/project... –  peterph Apr 30 at 14:40
    
@peterph, or even simpler ~/project. –  Stéphane Chazelas Apr 30 at 14:54
4  
With zsh, you can also do setopt cdablevars and then cd project –  Stéphane Chazelas Apr 30 at 14:56
    
@StephaneChazelas: I think that's a good point - though as it's specific to zsh perhaps you could add that as a separate answer? –  jmetz Apr 30 at 14:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.