Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm dealing with java projects which often result in deeply nested folders (/path/to/project/com/java/lang/whatever, etc) and sometimes want to be able to jump, say, 4 directory levels upwards. Typing cd ../../../.. is a pain, and I don't want to symlink. Is there some flag to cd that lets you go up multiple directory levels (in my head, it would be something like cd -u 4)? Unfortunately I can't find any man page for cd specifically, instead just getting the useless "builtins" page.

share|improve this question

4 Answers

Or... try this: (yay Google)

Navigate up the directory using ..n :

In the example below, ..4 is used to go up 4 directory level, ..3 to go up 3 directory level, ..2 to go up 2 directory level.

Add the following alias to the .bash_profile and re-login.

alias ..="cd .."

alias ..2="cd ../.."

alias ..3="cd ../../.."

(etc)

See Hack #2

share|improve this answer
2  
I would rather use the aliases .., ... and .... as they are faster to type, but the principle of aliases is the same of course. – Bernhard Jul 16 '12 at 20:24
@bernhard You're more than welcome to, as I don't believe it would cause any conflicts. I just left it as-is because I quoted it from the website. – ekaj Jul 16 '12 at 20:25

Turns out the correct answer is 'cd +n', where n is the number of levels you want to go up. Too bad this isn't documented anywhere!

share|improve this answer
If this is the correct answer go ahead and accept it – ekaj Feb 18 at 21:19
at least it does NOT work in bash. – Hongbo Zhu Mar 26 at 15:32

Not exactly what you're asking for but you should look into pushd and popd. I find them much more useful for folder navigation than some cd... alias

If you're going back and forth from a couple fixed areas, the usual thing is to have aliases.

alias proj1='cd /some/dir/containing/proj1'
alias proj2='cd /some/deeper/dir/structure/containing/proj2'
share|improve this answer

Do you know about autojump? It's a third party hack, but can be useful in your scenario.

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.