16

Possible Duplicate:
Can windows command line support Linux “cd -”?

Under Linux, I can use cd - to return to the last directory. How can I do that on Windows?

0

2 Answers 2

24

You can use the pushd and popd commands.

  • pushd <dir> will change directory from location a to location b
  • popd will change directory back to directory a

Example:

pushd %TEMP%     // go to user's temp dir, and remember
pushd \Windows   // go to windows dir, and remember
popd             // go back one dir, in this case the temp dir
popd             // go back one more dir, in this where you were before temp
2
  • 1
    It doesn't work for me, but using cd.. works, thanks to @Акула (below answer) Jul 6, 2017 at 6:14
  • cd .. goes one directory up. pushd/popd can be used to remember and go back the previous directory that you were at. It is often used in batch files where you want to remember the directory the user was at before starting the batch file, so you can return to it when you finish.
    – Abel
    Jul 25, 2020 at 23:52
6

Cmd.exe is an emulation layer for the old MS-DOS, commands are the same :

  1. One step backward = cd..
  2. All Backward = cd /

For the others look at some Ms-Dos table around the web

4
  • 5
    This is not what cd - does. If one is in /a/b/c/d then cd's to /a/e/f, cd - as a command returns you to /a/b/c/d, whereas cd .. moves you to /a/e and cd / moves you to /.
    – Neal
    Dec 18, 2009 at 15:18
  • 1
    You are right i've misunderstanded the question. (What poor figure!) :-(
    – Акула
    Dec 18, 2009 at 15:39
  • please remove this . cd .. goes up one level in folder hierarchy and not backwards in history. Also on win/dos the folder notation is backward slash (\) not forward slash (/)
    – elig
    Jul 7, 2020 at 22:45
  • @elig, you can use either backward or forward slash nowadays, so cd / is valid. Just not when you use it with pushd, for some odd reason. But I agree it is not an answer to the question.
    – Abel
    Jul 26, 2020 at 0:03

Not the answer you're looking for? Browse other questions tagged .