Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Say if I need to do this a lot:

cd ../../../../foo/sub1/bar/dest/
cd ../../../../foo2/sub1/bar/dest/
cd ../../../../foo3/sub1/bar/dest/
cd ../../../../foo/sub1/bar/dest/

Is there any faster way to not always typing ../../../../ so many times? Any creative ideas?

share|improve this question
why not just execute cd ../../../.. and be done with it? –  Red Cricket Dec 24 '13 at 4:09
You may enjoy pushd and popd or even cd -. –  jscott Dec 24 '13 at 4:28
If you're going that far back it might make sense to just cd /actual/path/you/want depending on how deep the folders go. –  Drew Khoury Dec 24 '13 at 5:06
This is a lot more effort than it's worth. If you're moving between directories, full path specification or just using cd - (to go to last directory) is easier. I typically alias h="history|grep" so that I can use the history entry shortcuts instead. Something like h foo3, followed by !450 to repeat that command. –  ewwhite Dec 25 '13 at 13:21
Open another terminal window and don't type cd ../../../.. at all –  Matt Dec 30 '13 at 2:29

4 Answers 4

up vote 18 down vote accepted

The classic way of doing this is setting the CDPATH variable. In your case it could be set to .:../../../../ or .:/path/to/the/parent/of/foo to achieve the desired effect. You can then simply do cd foo/sub1/bar/dest and get to where you want.

The advantage of this is that tab completion for cd also looks at $CDPATH and will magically work.

share|improve this answer

You can use autojump which automatically learn from previous cd command and you only need to specify unique string from full path next time. ex. j foo, j foo1, j foo2

share|improve this answer

You can create shortcuts for these commands by adding aliases into the bash configuration file (~/.bashrc or /etc/bash.bashrc)

alias cdd="cd ../../../../"

Then when you type cdd it will execute that command.

share|improve this answer
Yes, or function cdd () { cd ../../../../$1/bar/dest ; }, so then you can just type e.g. cdd foo, cdd foo2. –  Andrew Schulman Dec 24 '13 at 6:39

I recently came across, which lets you jump to a recently used directory by regex. So you could do something like:

z foo3.*dest

instead of:

cd ../../../../foo3/sub1/bar/dest/

(as long as you have visited that directory before, and nothing more recent / frequently used matches that regex)

share|improve this answer

Your Answer


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.