Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Having some problems googling this one because I'm not sure what the search term is. Shell scripting or terminal feature. What is the best way to streamline access to frequently used directories. Normally when I start a terminal it defaults to my home directory but sometimes I ike to open several terminal windows, the problem is I'm typing the cd /.../directory in each one multiple times and I need a way to not have to do this. What is the best way or just provide the search terms I could use to read about it online. Thank you

share|improve this question

migrated from stackoverflow.com Nov 11 '11 at 3:08

This question came from our site for professional and enthusiast programmers.

    
create alias for each directory that you very often use. Also use cd - to go back to last directory that you accessed –  Prince John Wesley Nov 10 '11 at 17:04

8 Answers 8

up vote 4 down vote accepted

Create a symbolic link in your home directory:

$ ln -s path/to/a/really/deeply/nested/director/my-project ~/my-project

$ cd ~/my-project
share|improve this answer

Add a variable in your .bashrc:

MYPROJECT=path/to/a/really/deeply/nested/director/my-project

to use:

$ cd $MYPROJECT
share|improve this answer

Set the CDPATH variable: it contains additional directories to be searched when you run cd.

share|improve this answer

You could use a bookmarks for the shell, e.g. bookmarks.sh.

share|improve this answer

You can also take advantage of CDPATH variable.

And you could define a bash function in your $HOME/.bashrc like

 # in file ~/.bashrc
 function work() {
    cd $HOME/path/to/a/really/deeply/nested/director/my-project
 }

And recent bash or even better zsh may permit you things like

 cd **/my-project

Assuming you have only one deeply nested my-project/ directory in all your tree hierarchy. The ** is doing the equivalent of a find so can be slow.

share|improve this answer

Add an alias in your .bashrc

alias myproject="cd path/to/a/really/deeply/nested/director/my-project"

to use:

$ myproject
share|improve this answer

You can also try autojump.

It is like cd command but with the ability to learn. It maintains a database of directories you visit and assign weight to each entry.

Later you can use j foo to jump to a directory that contains foo in its name. If more than few directories have foo, it will show you a list of matches from where you can select your desired directory.

share|improve this answer

The author of CDPATH recommends to export CDPATH to the environment. Please keep in mind that there is a strong chance that this will subtly break shell scripts that expect directories to be in one specific place. A remedy is to put CDPATH into ~/.bashrc and not export it. Your ~/.bashrc would look like this:

CDPATH=/var/:/etc/

Note that sourced shell scripts will still pick up CDPATH in this case. autojump is certainly a much safer alternative and more convenient to use than CDPATH.

share|improve this answer

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.