Windows PowerShell equivalent to Unix/Linux `pwd`?

31

3

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

warren

Posted 2011-06-09T13:22:28.173

Reputation: 8 599

in cmd just cd is enough. no need to echo %cd% – phuclv – 2017-02-27T03:58:11.943

Answers

36

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.

paradd0x

Posted 2011-06-09T13:22:28.173

Reputation: 7 771

1"that was easy" .. boy do I feel sheepish :) – warren – 2011-06-09T14:03:18.747

23

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;}

Rynant

Posted 2011-06-09T13:22:28.173

Reputation: 1 785

very cool! I need to find a good tutorial introduction to PowerShell – warren – 2011-06-09T14:04:18.073

1Hover over the Powershell tag in your question. Click the FAQ link. Look at the second item in the list. – EBGreen – 2011-06-09T14:19:56.387

4

Get-Location cmdlet should do the trick

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

Siim K

Posted 2011-06-09T13:22:28.173

Reputation: 6 776

3

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

Ion Todirel

Posted 2011-06-09T13:22:28.173

Reputation: 131

0

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

Peter Bauer

Posted 2011-06-09T13:22:28.173

Reputation: 101

1Hi Peter and welcome to SU! when indicating stuff that should be typed, use `backticks` (usually the top left corner of QWERTY keyboards below Esc) to put it in code formatting (or for long blocks, indent every line by four spaces) to improve legibility :) – Doktor J – 2020-01-17T19:49:18.233