486

How do I find the local path on Windows in a command prompt?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Joshua
  • 26,234
  • 22
  • 77
  • 106

12 Answers12

599

This prints it in the console:

echo %cd%

or paste this command in CMD, then you'll have pwd:

(echo @echo off
echo echo ^%cd^%) > C:\WINDOWS\pwd.bat
gsamaras
  • 71,951
  • 46
  • 188
  • 305
Petar Kabashki
  • 6,358
  • 1
  • 16
  • 8
  • 6
    i got access denied and searched for solution , it took time so switched to another answer `cd` only – shareef Jul 07 '15 at 20:18
  • 1
    This does not print the full directory name if you have accessed the directory via the ~ notation, e.g. "C:\PROGRA~3" – voutasaurus Jan 10 '16 at 04:52
  • 25
    Why do you need to `echo`? Just `cd` by itself seems to work fine. – Kevin Workman Feb 07 '18 at 05:20
  • 2
    `cd /?` says `Type CD without parameters to display the current drive and directory.` – phuclv May 01 '19 at 03:01
  • @shareef well when you wanna write into C:\windows you might need admin. but you could just write it somewhere you have permissions and add it to your path. the point of this second block is to basically have a pwd alias for convenience – My1 Oct 16 '20 at 22:07
  • 2
    if using as an argument to say `docker`, you can use ${PWD} if in windows powershell. `%cd` is fine if using Cmd prompt. – jimh Jan 12 '21 at 07:48
  • `echo %cd%` doesn't work when chaining commands, e.g. `cd C:\ && echo %cd%` -> wrong output. – serg06 Mar 16 '21 at 00:51
  • This doesn't work with `doskey` though. If you do `doskey pwd=echo %cd%` you'll permanently have it set to the working directory _when the `doskey` was run_. The correct approach is `doskey pwd=cd`. – ADTC Sep 12 '21 at 09:33
  • 1
    It doesn't work in PowerShell, so not very robust for all window users – Eric Burel Feb 21 '22 at 11:07
  • `cmd /C echo %cd%` will work in both CMD and PowerShell – shukebeta Mar 14 '23 at 22:28
167

It is cd for "current directory".

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • 10
    If you need it in a variable or so, using the %CD% pseudo-variable is probably easier. – Joey May 28 '09 at 16:32
  • 30
    Cute, but `cd` is for "change directory" – Daniel Stevens Aug 31 '18 at 09:28
  • 12
    Related side note: While on Windows `cd` alone will print the current working directory, on Linux it will change to your user's home directory without printing anything. So beware if you're looking for something cross platform. – Daniel Stevens Aug 31 '18 at 09:29
  • 2
    @DanielStevens the help line from `cd` says *Displays the name of or changes the current directory.* – phuclv May 01 '19 at 03:00
  • 1
    @phuclv correct, the *Windows* documentation for [cd](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cd) does say that. The *Linux* documentation for [cd](http://linuxcommand.org/lc3_man_pages/cdh.html) says that when no path is given, it will change to your home directory. My local man pages use the wording: *"Change the current directory to dir. if dir is not supplied, the value of the HOME shell variable is the default."* – Daniel Stevens May 02 '19 at 10:09
30

Open notepad as administrator and write:

@echo %cd%

Save it in c:\windows\system32\ with the name "pwd.cmd" (be careful not to save pwd.cmd.txt)

Then you have the pwd command.

Joseph Stine
  • 1,022
  • 1
  • 12
  • 23
Fernando
  • 335
  • 3
  • 2
27
cd ,

it will give the current directory

D:\Folder\subFolder>cd ,
D:\Folder\subFolder
phuclv
  • 37,963
  • 15
  • 156
  • 475
user4350567
  • 311
  • 3
  • 3
  • 11
    just `cd` is enough. The comma is useless – phuclv Feb 27 '17 at 03:58
  • 3
    in cmd [`,`, `;`, `=` are also delimiters just like space and tab](https://ss64.com/nt/syntax-esc.html), therefore `cd ,` is no different from `cd =;=` or `cd ` – phuclv May 11 '19 at 02:37
  • Doesn't work anymore on Windows 10 – Eric Burel Feb 21 '22 at 11:13
  • @EricBurel it works in cmd. It has nothing to do with Windows 10 because it's a shell feature, and if you use a different shell like powershell then obviously it won't work. Each shell has different syntax and powershell is the default in many new installations – phuclv Jul 21 '23 at 01:54
16

cd without any parameters is equivalent to pwd on Unix/Linux.

From the console output of typing cd /?:

Displays the name of or changes the current directory.

[...]

Type CD without parameters to display the current drive and directory.
Roy Tinker
  • 10,044
  • 4
  • 41
  • 58
8

You can just type

cd

it will return you the current path.

phuclv
  • 37,963
  • 15
  • 156
  • 475
samivic
  • 1,216
  • 14
  • 13
  • this is exactly like Daniel A. White's answer above. Why on earth duplicated answers on this got so many upvotes – phuclv Jul 21 '23 at 01:57
2

In PowerShell pwd is an alias to Get-Location so you can simply run pwd in it like in bash

It can also be called from cmd like this powershell -Command pwd although cd or echo %cd% in cmd would work just fine

phuclv
  • 37,963
  • 15
  • 156
  • 475
1

It will show you the current path in the console, use the below command

echo %cd%

enter image description here

Fazal Haroon
  • 845
  • 2
  • 10
  • 20
0

hmm - pwd works for me on Vista...

Final EDIT: it works for me on Vista because WinAvr installed pwd.exe and added \Program Files\WinAvr\Utils\bin to my path.

sean e
  • 11,792
  • 3
  • 44
  • 56
  • 1
    Nor vista. Are you using powershell? – Daniel A. White May 28 '09 at 16:50
  • I'm not using powershell. I seem to recall something about command extensions but can't find a checkbox anywhere for that. I've also got completion in my Command Prompt. I could swear there used to be an applet in Control Panel to enable command extensions but I can't find it now. – sean e May 28 '09 at 17:26
  • Command extensions are enabled by default on Windows NT and later. Tab completion is separate from that and was available from Windows 2000 onwards and enabled by default since XP. pwd only works here because I have a pwd.cmd with "echo %cd%" in my path. You can use gcm pwd in Powershell to check where it comes from on your machine (sort of like which(1), only better). – Joey May 28 '09 at 19:44
  • gcm pwd reports that pwd is an Alias with a definition of Get-Location. – sean e May 28 '09 at 20:08
  • 2
    Late to the party but usually you can figure out the location where pwd is coming from by the command 'where' on command prompt. – veepsk Sep 25 '15 at 14:15
-1
C:\Documents and Settings\Scripter>echo %cd%
C:\Documents and Settings\Scripter

C:\Documents and Settings\Scripter>

for Unix use pwd command

Current working directory

phuclv
  • 37,963
  • 15
  • 156
  • 475
-2

Use the below command

dir | find "Directory"
phuclv
  • 37,963
  • 15
  • 156
  • 475
  • this won't work if there's a file or folder named "Directory" in the current directory, or if Windows language is not English, because output of `dir` is localized – phuclv May 01 '19 at 03:07
-4

You can simply put "." the dot sign. I've had a cmd application that was requiring the path and I was already in the needed directory and I used the dot symbol.

Hope it helps.

Mastereve
  • 1
  • 2