Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

For example, I do the following cds in succession-

cd /tmp
cd /home/admin
cd /root/
cd /some_other/directory

Now I am in /some_other/directory. Now, is there anyway to go back to /tmp, the directory from where I started, from the command line? Just like we navigate directories using the back button in the GUI?

cd - just takes me one level back.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

This is shell specific. In a pure POSIX shell, you can't without typing cd /tmp again. In csh, tcsh, bash or zsh, you can use pushd instead of cd to change directories and then popd +1 to cd to the first directory you pushed onto the stack.

share|improve this answer

Read this article from LinuxGazette on adding a history to cd with a few simple scripts. It's quite usable.

If you want to be fancy, then there is a program called autojump (homepage here) which keeps history of the directories visited, provides shortcuts and generally supports "intelligent" cd.

autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line. The jumpstat command shows you the current contents of the database. You need to work a little bit before the database becomes usable. Once your database is reasonably complete, you can “jump” to a commonly "cd"ed directory by typing: j dirspec

share|improve this answer

I was looking for the same problem and came across below workaround/shortcut for changing n directories back. Hope it would help for next visitor here.

Just add the following to the bash_profile if you are using a bash shell. For other shell's use it according to their syntax.

    alias ..="cd .."
    alias ..2="cd ../.."
    alias ..3="cd ../../.."
    alias ..4="cd ../../../.."
    alias ..5="cd ../../../../.."

    # cd /tmp/very/long/directory/structure/that/is/too/deep
    [Note: use ..4 to go up 4 directory level]
    # pwd

You can also use just dots instead of dots followed by a number. Detailed description is available in the below link.

Source :

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.