Windows PowerShell equivalent to Unix/Linux `pwd`?

67,625

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

Share:
67,625

Related videos on Youtube

David Yates
Author by

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, 2022

Comments

  • David Yates
    David Yates over 1 year

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

  • David Yates
    David Yates almost 13 years
    "that was easy" .. boy do I feel sheepish :)
  • David Yates
    David Yates almost 13 years
    very cool! I need to find a good tutorial introduction to PowerShell
  • sean christe
    sean christe almost 13 years
    Hover over the Powershell tag in your question. Click the FAQ link. Look at the second item in the list.
  • Doktor J
    Doktor J over 4 years
    Hi 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
    Christian Kaiser over 3 years
    Not exactly, Use Get-Location | Foreach-Object { $_.Path } to get only the path as in Linux pwd