Change directory to previous directory in Powershell

historypowershell

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?

Best Answer

I've had differing luck with cd +/- even though it should work.

pushd and popd 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 to Push-Location and Pop-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.