Hack 4. Use “cd -” to toggle between the last two directories

You can toggle between the last two current directories using cd – as shown below.

# cd /tmp/very/long/directory/structure/that/is/too/deep

# cd /tmp/subdir1/subdir2/subdir3

# cd -

# pwd
/tmp/very/long/directory/structure/that/is/too/deep


# cd -

# pwd
/tmp/subdir1/subdir2/subdir3

# cd -

# pwd
/tmp/very/long/directory/structure/that/is/too/deep

Comments on this entry are closed.

  • prabhs June 17, 2012, 10:08 pm

    Super

  • Freddy Bob August 16, 2013, 8:20 am

    I use this with an alias

    alias -=”cd -”

    to flip swap current and previous directories