Windows PowerShell equivalent to Unix/Linux `pwd`?

In follow-up to the cmd.exe question, what is the PowerShell equivalent to echo %cd%, or Linux/Unix pwd?

1

5 Answers

PowerShell has many of the same commands as Linux. pwd is the command equivalent.

When you type pwd in Powershell, it is an alias to Get-Location.

2

In addition to Get-Location and its Aliases, you can also use the automatic variable $pwd.

The $pwd variable is nice because you have direct access to the PathInfo members. E.g.

$pwd.Path.PadLeft(80)
$pwd.Drive

And if you ever want to know what members there are you can just pipe the command\alias to Get-Member :

PS C:\Users\your-name-here\Desktop> pwd|Get-Member TypeName: System.Management.Automation.PathInfo
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Drive Property System.Management.Automation.PSDriveInfo Drive {get;}
Path Property System.String Path {get;}
Provider Property System.Management.Automation.ProviderInfo Provider {get;}
ProviderPath Property System.String ProviderPath {get;}
2

It's pwd. You can "stringify" it by putting it in the quotes. More so, you can build up paths like so: "$pwd\bin".

1

Get-Location cmdlet should do the trick

As Thiago mentioned, you can use these aliases: gl or pwd

If you only need the Path as Text without the usual header:
(gl).Path /* is a short form for Get-Location with the object Path,
or (pwd).Path

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like