Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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
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 : http://www.thegeekstuff.com/2008/10/6-awesome-linux-cd-command-hacks-productivity-tip3-for-geeks/

share|improve this answer
That's not what they asked though... Also, you can make it easier with a subroutine: back () { for i in `seq 0 $1`; do cd ../; done } and then call back 3 for example. But the question asker wanted to know how to go several cd history steps back. – Matt Fletcher Jan 6 at 15:35
Thanks for the heads up.. I was thinking this is one way of jumping from current directory to where he started if he remember how many directories he passed by. Your subroutine call is nice, its much easier to define and use. – MVSR Feb 26 at 4:39

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.