The Windows equivalent of the Unix 'pwd' command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
4 min

banner

# The Windows equivalent of the Unix 'pwd' command

The Windows cd command is the equivalent of the Unix pwd command. When the cd command is used without specifying any parameters, it displays the current drive and directory.

Click on the Search bar, type "cmd" and open the Command Prompt.

cmd
cd

running cd command on windows

The cd command is used to display the name of the current directory or change the current directory.

If you use the cd command without providing any parameters, it displays the current drive and directory.

You can look at other examples of using the cd command in this section of the docs.

For example, the cd\ command can be used to return to the root directory.

cmd
cd\

using cd to return to root directory

If you need to change to a directory that contains spaces in its name, enclose the path in double quotes.

cmd
cd "Documents and Settings"

using cd with directory with spaces

If you get a permissions error, you have to open CMD as an administrator to run the cd command.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

  1. Now you will be able to use the cd command to display the current directory and change to any directory.

An alternative to consider is to use PowerShell where the pwd command is available

# Using the pwd command on Windows in PowerShell

To use the pwd command on Windows in PowerShell:

  1. Click on the Search bar and type "PowerShell".

start powershell

  1. Click on the "Windows PowerShell" application.

Use the pwd command directly in PowerShell to display the current drive and directory.

PowerShell
pwd

windows powershell pwd command

If you need to open PowerShell in a specific folder:

  1. Open the folder in a window.
  2. Press Shift and right-click in Explorer.

windows open powershell window here

  1. Click on "Open PowerShell window here".
  2. Run the pwd command.

The pwd command in PowerShell is an alias for the Get-Location command.

PowerShell
Get-Location

If you get a permissions error, you have to run PowerShell as an administrator.

To run PowerShell as an administrator:

  1. Click on the Search bar and type "PowerShell".
  2. Right-click on the "PowerShell" application and click "Run as administrator".

run powershell as administrator

  1. Now you will be able to use the pwd command to display the current directory.
Alternatively, you can run the pwd command in Git Bash by installing git on your Windows machine.

If you already have git installed, you can search for Git Bash and use the pwd command, otherwise, you have to install git first.

# Running the pwd command on Windows in Git Bash

To download git and be able to use Git Bash:

  1. Open the git downloads page and download the installer for Windows.
  2. Start the installer.
  3. You will be prompted to select a destination location. You can leave the default option and click Next.

git select destination location

  1. You will be prompted to select components on the next screen. Leave the default options and click Next.

git select components

  1. Click Next on the screen that prompts you to "Select Start Menu Folder".

  2. On the next screen, you can choose the default editor for Git, e.g. Notepad, Notepad++ or any other editor you prefer.

choose git default editor

  1. On the "Adjust the name of the initial branch in new repositories screen", click Next.

adjust name of initial branch

  1. On the "Adjust your PATH environment" screen, make sure you have the default option of "Git from the command line and also from 3rd-party software" option selected and click "Next".

adjust your path environment

  1. For all the remaining screens, leave the default option selected and click Next.
  2. Lastly, click on the Install button to install git.

Once you have git installed, click on the Search field, type "Git Bash" and start the application.

search for git bash

Now you can use the pwd command directly in Git Bash.

GitBash
pwd

using pwd command in git bash

If you need to open Git Bash in a specific folder:

  1. Open the folder in a new window.
  2. Right-click in Explorer.

open git bash in folder

  1. Click "Git Bash Here".

Now you can use the pwd command to display the current drive and directory.

GitBash
pwd

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.