Last Updated: February 25, 2016
·
2.606K
· mikestreety

Linux - return to the last folder

If you need to cd out of a folder you are so nicely nestled in and will need to go back, you might find yourself typing pwd and copying and pasting.

There is a nice little command in Linux (and Mac) that will drop you back into your last folder - saves the copying and pasting!

cd -

4 Responses
Add your response

See also pushd and popd.

over 1 year ago ·

@xtagon - I get a bash: pushd: no other directory and bash: popd: directory stack empty when using those two

over 1 year ago ·

Ahh, just worked out you used pushd instead of cd e.g.

pushd /home/user
pushd /home
popd #takes you back to /home/user
over 1 year ago ·

Yep. I use them so often I alias them:

alias pu='pushd'
alias up='popd'

You can also use the dirs command to see the stack.

over 1 year ago ·