I am a Linux guy, but am trying to be open-minded and learn some Powershell. I miss the ability to cd -
back to a previous directory, like in *nix shells. Is there a similar command in Powershell—one that would allow me to return to my previous directory?
Change directory to previous directory in Powershell
historypowershell
Related Question
- Shell – PowerShell script to copy files is having issue with directory path with spaces in it
- PowerShell History – How to View Full History, Not Just Current Session
- Powershell Auto Complete Settings – How to Configure
- Linux – Remote connect to a Windows via PowerShell in Linux
- Shell – PowerShell command for ffmpeg to process items in a folder recursively
Best Answer
I've had differing luck with cd +/- even though it should work.
pushd
andpopd
have been around a long time and do the job nicely but I wasn't sure if they were officially supported in Powershell - I've just discovered they are actually aliases toPush-Location
andPop-Location
so are current and supported, seems to be the best way to go:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/push-location?view=powershell-7 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/pop-location?view=powershell-7
Previous suggested of using aliases to swap out the standard
cd
command are a good idea but in scripting I'm just using the real cmdlet name for clarity.