Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any command / tool to navigate previous directory in windows command prompt?

In linux usually use

cd -

for previous directory navigation.

share|improve this question

9 Answers 9

up vote 9 down vote accepted
+50

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 doskey macro:

C:\>doskey cd=mycd $*

The only caveat is if you omit the space between cd and .. or \, you will get the builtin version of cd not the doskey macro... and you still have to remember not to use C:, D: etc. to change drive.

share|improve this answer
    
It looks like it shouldn't work, but it does. OLDPWD gets set correctly. –  Hugh Allen May 18 '10 at 7:52
1  
+1 This is nice , it works! but painful to use mycd (or whtevr ) –  ukanth May 18 '10 at 10:13
    
@TiNS: true. Answer updated. –  Hugh Allen May 18 '10 at 13:13
    
Thanks for the updated answer, let me check it –  ukanth May 18 '10 at 14:24
    
@HughAllen can make a doskey macro for cd\ and cd.. doskey cd\=cd \ or doskey cd\=c:\mycd.bat \ doskey C:=c:\mycd.bat C: –  barlop Nov 7 '11 at 13:13

You can use pushd and popd:

C:\WINDOWS>pushd \
C:\>popd
C:\WINDOWS>
share|improve this answer
    
Thx John, But this is not exactly what i am looking for. –  ukanth May 17 '10 at 16:24
1  
It's exactly what I want for my batch scripts, thanks. It even changes drives without needing the \d switch –  Deebster Feb 8 '12 at 10:59

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                             
$ 
share|improve this answer

There's a freeware cmd clone with extra features including cd - called Take Command Console LE.

alt text

share|improve this answer
    
This doesn't work –  ukanth May 19 '10 at 2:39
    
@TiNS: OK I just tried it and it worked for me. What did it do for you? –  Hugh Allen May 19 '10 at 3:11
    
I tried with console (from main window) –  ukanth May 19 '10 at 12:29
    
@TiNS: I'm not clear on what you did, but maybe this screenshot will help? (answer updated) –  Hugh Allen May 19 '10 at 12:51

if you are running the batch file you can use

  cd /D  %~dp0

This will jump back to the original path from where the batch file was run

share|improve this answer

Perhaps this is what you are looking for.

If you have:

C:\Users\John Doe> 

and you want to go back to C:\, just type:

C:\Users\John Doe>cd C:\

Result:

C:\
share|improve this answer
    
Nope.​​​​​​​​​​ –  Synetech Nov 30 '12 at 18:12

Depending what your goal is, you could just start a new cmd session by doing 'cmd', move directory and do whatever you want, when you then do 'exit' to leave the session you'll be back in the directory you were when you started the new session.

share|improve this answer

C:\Users\Shreyasa>cd..

C:\Users>

share|improve this answer
2  
This is incorrect. cd.. changes to the directory one level above the current directory, not the previous directory. –  John Bensin Sep 27 '13 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.