Mastering pushd and popd in Windows Command Line

Tired of navigating back and forth between folders in Command Prompt like some kind of file system tourist?
Wish you could teleport to a directory, do your work, and snap right back to where you started — instantly?

Say hello to your new best friends: pushd and popd.


What Are pushd and popd?

In short:

  • pushd = Go to a new directory, but remember where you were
  • popd = Teleport back to the place you pushed from

They work together like a bookmark system for your terminal sessions.


Basic Syntax

cmd
pushd [path]

and then later:

cmd
popd

Example 1: Basic Usage

Let’s say you’re working in:

cmd
C:\Users\John\Documents

You need to quickly jump to:

cmd
D:\Projects\SuperApp\src

Instead of typing cd manually twice, you can do:

cmd
pushd D:\Projects\SuperApp\src

Now you’re in D:\Projects\SuperApp\src.

After you finish your work, just type:

cmd
popd

Now you’re in D:\Projects\SuperApp\src.

After you finish your work, just type:

cmd
C:\Users\Zaur\Documents

No need to remember the old path or type it again!

Example 2: Using in Batch Scripts

If you’re writing a batch file, pushd and popd are lifesavers for keeping your scripts tidy and avoiding messy directory changes.

Example:

BAT (Batchfile)
@echo off
pushd D:\Builds\ProjectX
echo Compiling ProjectX...
:: build commands here
popd
pushd D:\Builds\ProjectY
echo Compiling ProjectY...
:: more build commands here
popd

✅ Each pushd goes into a directory
✅ Each popd brings you back exactly where you were before
✅ No worries about “Where am I now?” errors

🔄 Bonus: pushd + Network Shares

Here’s something cool: If you pushd to a network path, Windows automatically maps it to a temporary drive letter!

Example:

cmd
pushd \\Server\Share

Windows might map it as:

cmd
Z: -> \\Server\Share

Super handy when scripting file copies or installs across network shares.

(And popd will clean up that temp drive mapping when you’re done. Beautiful.)

In a nutshell:

CommandWhat It Does
pushd C:\FolderJump to C:\Folder and save current path
popdReturn to the saved path
pushd \\Server\ShareMap network share and move into it
popd after network pushdDisconnect the temporary drive letter

💡 Why Should You Use Them?

  • Save time when bouncing between directories
  • Avoid messy manual cd navigation
  • Write cleaner, safer batch files
  • Automate scripts that interact with multiple paths
  • Feel like a command-line wizard ✨

📜 Cheat Sheet

BAT (Batchfile)
pushd C:\Temp\Work
:: do some work here
popd
:: you're back at your starting point
BAT (Batchfile)
pushd \\Server01\Shared
copy importantfile.txt .
popd

Final Thoughts

pushd and popd are tiny commands that pack a huge punch in daily scripting, troubleshooting, and workflow management.

Once you start using them, you’ll wonder how you ever lived without this command-line teleportation magic.

💬 Have a favorite pushd trick or a network drive story? Drop it in the comments — or challenge yourself to go a full day without using cd!

Leave a Comment