9

In Linux we can use cd - to enter the previous directory, like:

/home/user: cd /a

/a: cd -

/home/user:

The - means the latest previous directory.

0

4 Answers 4

12

You can use pushd and popd:

c:\> pushd c:\windows
c:\Windows> popd
c:\>
2
  • you can use those on *nix systems too, and they're not limited to just "last directory". the windows versions also have some nifty sideeffects like auto-mounting network shares and such. Dec 11, 2009 at 6:34
  • 1
    Yes, but don't forget the popd after you pushd'd an UNC path, otherwise the temporary share will linger around :-)
    – Joey
    Dec 11, 2009 at 7:00
4

Windows command-line by itself, no...

But, if needed / interested, you might want to try something like Cygwin or Msys, which will allow you to use a Linux-shell on Windows.

Not sure it's really what you want, but it might solve some or your problems.

(The other solution being to just... use Linux ^^ )

0
3

Maybe you would be interested in this: https://gist.github.com/programus/2d2738b2a746140186f7738b678bdcec

Of course, pushd/popd are great pair of commands, but it cannot switch back once you popped the previous out.

So I made one batch myself, which could maintain a directory history for jumping back, because I have to jump among many directories very often.

Here is the help:

cdx                 - display all saved path with leading id and name followed if any
cdx <path>          - save current path and jump to <path>
cdx :<n|name>       - jump to the Nth or named path in the saved list
cdx :               - jump to previous path
cdx <n>:<name>      - name the Nth path as <name>
cdx rm [:]<n|name>  - remove the Nth or named path from the list
cdx clear           - clear the list
cdx /help           - print out this help
cdx /?              - same as above

and examples

D:\>cdx "C:\Program Files"
C:\Program Files>cdx
[1] D:\

C:\Program Files>cdx d:\tmp
d:\tmp>cdx
[1] D:\
[2] C:\Program Files

d:\tmp>cdx t:\UsrTmp
t:\UsrTmp>cdx .
t:\UsrTmp>cdx
[1] D:\
[2] C:\Program Files
[3] d:\tmp
[4] t:\UsrTmp

t:\UsrTmp>cdx :2
C:\Program Files>cdx
[1] D:\
[2] C:\Program Files
[3] d:\tmp
[4] t:\UsrTmp

C:\Program Files>cdx rm 1
C:\Program Files>cdx
[1] C:\Program Files
[2] d:\tmp
[3] t:\UsrTmp

C:\Program Files>cdx name 3:tmp
C:\Program Files>cdx
[1] C:\Program Files
[2] d:\tmp
[3] t:\UsrTmp   <--<<< (tmp)

C:\Program Files>cdx :tmp
t:\UsrTmp>cdx :
C:\Program Files>
3

A simple note for those using Cmder (It's really cool alternative for cmd, by the way.)

I use aliases for bash-like interface, something like this:

C:\Users\myname> cd test-dir
C:\Users\myname\test-dir> cd-
C:\Users\myname>

You can set aliases in %CMDER_ROOT%\config\user-aliases.cmd

cd=pushd . & cd $*
cd-=popd

You must log in to answer this question.

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