Is there any command / tool to navigate previous directory in windows command prompt?
In linux usually use
for previous directory navigation.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Save the following to eg.
mycd.bat somewhere in your path:
@echo off if '%*'=='' cd & exit /b if '%*'=='-' ( cd /d %OLDPWD% set OLDPWD=%cd% ) else ( cd /d %* if not errorlevel 1 set OLDPWD=%cd% )
Then always remember to use
mycd instead of
cd to change directories and drives.
Alternatively, use a
C:\>doskey cd=mycd $*
The only caveat is if you omit the space between
\, you will get the builtin version of
cd not the
doskey macro... and you still have to remember not to use
D: etc. to change drive.
If you want the exact behavior of bash, why not use bash? I have cygwin installed and it is very nice. It doesn't make you stick to its UNIX tools - it will happily call any windows executable. For
cmd.exe builtins you can create an alias:
hugh@comp07 ~/testdir $ alias cm='cmd /c' hugh@comp07 ~/testdir $ cm dir Volume in drive C has no label. Volume Serial Number is AC2A-8378 Directory of C:\cygwin\home\hugh\testdir 18/05/2010 02:02 PM <DIR> . 18/05/2010 02:02 PM <DIR> .. 0 File(s) 0 bytes 2 Dir(s) 1,365,155,840 bytes free hugh@comp07 ~/testdir $
There's a freeware
cmd clone with extra features including
cd - called Take Command Console LE.
The accepted answer is very great for the requirement. While I often have to switch among many recent directories instead of just just two (current and previous).
So I recently made a batch to make my daily jobs easier. https://gist.github.com/programus/2d2738b2a746140186f7738b678bdcec
I've been using this little-known program for directory changing on Linux and Windows for over 12 years and I really don't understand why many more people don't use it because it's brilliant.
CD Deluxe lets you change to the last directory with
cd - and you can go to the second last directory with
cd -2 and the third with
cd -3 and do on. Just
cd will give you the directory history.