Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Modifying bash to interpret cd ... where the number of '.' would be the number of levels to go up. Would this cause a conflict that I'm not aware of? – JS. Apr 19 at 17:48

10 Answers 10

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 ../../.."


See Hack #2

share|improve this answer
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. – cutrightjm Jul 16 '12 at 20:25
The 4DOS.EXE shell for DOS also supported cd ..., cd .... etc. It was very handy. – Alexios Jul 25 '13 at 21:43

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 – cutrightjm Feb 18 '13 at 21:19
at least it does NOT work in bash. – HongboZhu Mar 26 '13 at 15:32
Doesn't work on bash 4.2.25 as shipped with Debian. Out of curiosity, what *nix and/or shell are you using? – Alexios Jul 25 '13 at 21:44
Bash has a built-in called dirs that takes [+n] as an argument, and prints the nth unique directory that was added via pushd. If you alias cd to pushd, then you can use this. However, note that this is not technically an answer to the OP's question, because this has to do with unique directories, meaning that the order gets messed up over time, as you return to the same directories. – Brian Peterson Oct 15 '13 at 18:07
Yeah, pushd and popd also take a [+n] option, which is why that is able to work. Also, though it's imperfect and indirect, I guess this can be used as an answer to the question. Often you visited the directories above you recently, so they will be in the last 10 dirs stored by the directory stack. – Brian Peterson Oct 15 '13 at 18:15

Make alias in you ~/.bashrc

function cd_up() {
  cd $(printf "%0.s../" $(seq 1 $1 ));
alias 'cd..'='cd_up'

and use:

$ cd.. 10
share|improve this answer
Nice one! Works for me! Bash 4.3.11 – Carlos Nunez Sep 18 '15 at 18:29

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

A simple, low-tech solution that doesn't need any setup. Only works in shells with bash-style command editing, though.

  • Type cd ..
  • Press Up-arrow Return as many times as needed. Very fast if you use two fingers.
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

Instead of using aliases you could also use the following bash function:

function mcd() {

  for ((i=1; i<=$1;i++)); do

  cd $up

(or as a one-liner: function mcd() { up=""; for ((i=1; i<=$1;i++)); do up="${up}../"; done; cd $up; })

Adding this to your ~/.bashrc file will make it available in your terminal and the building of a String ../../../../../../ before calling cd will also make it possible to use cd - to jump back to the start directory.

A more helpful implementation could also contain some user-input checks:

function mcd() {
    if [[ $1 -lt 1 ]]; then
        echo "Only positive integer values larger than 1 are allowed!" >&2
        echo -e "\n\tUsage:\n\t======\n\n\t\t# to go up 10 levels in your directory\n\t\tmcd 10\n\n\t\t# to go up just 2 levels\n\t\tmcd 2\n" >&2
        return 1;


    for ((i=1; i<=$1;i++)); do

    cd $up
share|improve this answer

Try the rarely used environment parameter CDPATH. Then you might not have to explicitly set the level.


$ find workspace -type d

$ CDPATH=".:~/workspace:~/workspace/project1:~/workspace/project1/com:~/workspace/project1/com/java:~/workspace/project1/com/java/lang"
$ cd com
$ pwd

If working on multiple projects, you can make the CDPATH setting into a project specific environment file. And trigger it with a shim for additional automation.

I tend to use pushd and popd quite a lot. I tend to use CDPATH to let me hop between project trees rather than subdirs in a project - but at the moment I'm working on a lot of small projects, not a few big projects. :)

share|improve this answer

If you are previously on the target directory:

luna:/tmp % mkdir -p a/b/c/d
luna:/tmp % pwd
luna:/tmp % cd a/b/c/d
luna:d % pwd
luna:d % cd -
luna:/tmp % pwd
luna:/tmp % 
share|improve this answer

Take a look at DirB. It's a BASH script that allows you to create bookmarks as follows:


  • s Save a directory bookmark
  • g go to a bookmark or named directory
  • p push a bookmark/directory onto the dir stack
  • r remove saved bookmark
  • d display bookmarked directory path
  • sl print the list of directory bookmarks

Very simple, very effective.

share|improve this answer

You must log in to answer this question.

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