14

Is there a way to go to any directory from any other directory directly? For example, lets say that I'm at root and I wanted to go directly to currentProject without doing:

cd dropbox/dev/currentProject



-root
  -dropbox
     -dev
        -currentProject

Is there way to do this?

7 Answers 7

21

You can use something like autojump. Autojump lets you quickly jump to frequently visited directories with the j command.

For instance, once you've cd'd into your currentProject directory a few times, you can jump to it like this:

j currentProject

You can even use just part of the directory name. So you could do:

j current

To cd into currentProject.

8

You can also add some common directories to your $CDPATH

export CDPATH=$HOME

This for example will let you cd into any dir in your home folder from anywhere in your system.

more

6

This doesn't answer your question directly, but if I'm inferring correctly that you're going to be jumping between directories a lot, you could use a terminal multiplexer like GNU Screen to keep the different directories open in different windows, and simply switch between them as needed. I personally use Byobu, which adds some functionality on top of screen.

1
5

You can set an alias in your bash profile. Basically that lets you abbreviate a command with a word. You could set currentProject actually point to /dropbox/dev/currentProject

4

You could create symlinks in your home directory to where you want to go.

ln -s /dropbox/dev/currentProject ~/currentProject

This way, you're still using cd, but you don't have to remember the full path. Just use:

cd ~/currentProject

When you stop using the link, just delete it.

rm ~/currentProject
0

As Wuffers mentioned above, autojump that can do this for you. It stores a database of previously visited directories and lets you use a command like j <a few letters in the directory path> to move to that directory. There is an additional command for autojump named jc that should meet your requirements. jc lets you jump to a previously visited subdirectory of the current working directory. So you only have to visit the directory once for this to work until you purge the autojump database. Also, you can also add it directly instead with autojump --add DIR (perhaps building the add list from a directory tree listing if needed).

0

In bash and *csh, there is the builtin commands 'pushd' and 'popd' that allow you to push directories onto a Last In First Out stack (with pushd [directory]) and then quickly change to the top directory in the stack using 'popd'. So, depending on how you loaded the stack, you might be able to quickly navigate between directories suitably well for this to be functional for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .