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

by Ramesh

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

  1. # cd /tmp/very/long/directory/structure/that/is/too/deep
  2.  
  3. # cd /tmp/subdir1/subdir2/subdir3
  4.  
  5. # cd -
  6.  
  7. # pwd
  8. /tmp/very/long/directory/structure/that/is/too/deep
  9.  
  10.  
  11. # cd -
  12.  
  13. # pwd
  14. /tmp/subdir1/subdir2/subdir3
  15.  
  16. # cd -
  17.  
  18. # pwd
  19. /tmp/very/long/directory/structure/that/is/too/deep