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 werepopd
= Teleport back to the place you pushed from
They work together like a bookmark system for your terminal sessions.
Basic Syntax
pushd [path]
and then later:
popd
Example 1: Basic Usage
Let’s say you’re working in:
C:\Users\John\Documents
You need to quickly jump to:
D:\Projects\SuperApp\src
Instead of typing cd
manually twice, you can do:
pushd D:\Projects\SuperApp\src
Now you’re in D:\Projects\SuperApp\src
.
After you finish your work, just type:
popd
Now you’re in D:\Projects\SuperApp\src
.
After you finish your work, just type:
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:
@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:
pushd \\Server\Share
Windows might map it as:
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:
Command | What It Does |
---|---|
pushd C:\Folder | Jump to C:\Folder and save current path |
popd | Return to the saved path |
pushd \\Server\Share | Map network share and move into it |
popd after network pushd | Disconnect 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
pushd C:\Temp\Work
:: do some work here
popd
:: you're back at your starting point
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
!