Windows PowerShell equivalent to Unix/Linux `pwd`?
Solution 1
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
.
Solution 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;}
Solution 3
Get-Location
cmdlet should do the trick
As Thiago mentioned, you can use these aliases: gl
or pwd
Solution 4
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
Related videos on Youtube
David Yates
I'm a hobbyist programmer, part-time sysadmin, and full-time analytics, big data, data center management, automation, and cloud computing architect and delivery engineer.
Updated on September 18, 2022Comments
-
David Yates over 1 year
In follow-up to the cmd.exe question, what is the PowerShell equivalent to
echo %cd%
, or Linux/Unixpwd
? -
David Yates almost 13 years"that was easy" .. boy do I feel sheepish :)
-
David Yates almost 13 yearsvery cool! I need to find a good tutorial introduction to PowerShell
-
sean christe almost 13 yearsHover over the Powershell tag in your question. Click the FAQ link. Look at the second item in the list.
-
Doktor J over 4 yearsHi 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 :) -
Christian Kaiser over 3 yearsNot exactly, Use
Get-Location | Foreach-Object { $_.Path }
to get only the path as in Linux pwd