Linux Command Reference ยท Files and Directories
Linux pwd command
Reference for pwd: print the current working directory, the difference between logical (-L) and physical (-P) paths, and how it relates to $PWD.
pwd prints the absolute path of the current working directory. Bash has it as a builtin, and a separate program /bin/pwd exists as well. The two can differ in one respect: how they treat symbolic links in the path.
The builtin reads the shell variable PWD, which cd keeps up to date. If you reached the directory through a symlink, the default (-L, logical) output still shows the link name. With -P (physical) every symlink is resolved and you see the real location on disk.
pwd [-L|-P]
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
pwd [-L | -P]
| Name | Description |
|---|---|
-L |
Print the logical path as stored in $PWD, keeping symlink names. This is the default for the builtin. |
-P |
Print the physical path with all symlinks resolved. |
Returns: 0 on success; non-zero if the current directory cannot be determined or the options are invalid.
Usage notes
pwdversus$PWD:$PWDis the same text without starting a command. Inside a script,"$PWD"is the cheapest way to read the current directory;$(pwd)works but adds a subshell.- The program
/bin/pwd(GNU coreutils) defaults to physical output unlessPOSIXLY_CORRECTis set, while the builtin defaults to logical. Usepwd -Porpwd -Lexplicitly when it matters. pwd -Pandrealpath .give the same result for the current directory. For any other path userealpath.- Quote the result. Directory names can contain spaces:
cd "$(pwd)", notcd $(pwd). - Deleted directories: if the current directory was removed,
pwd -Lmay still print the old name from$PWD, butpwd -Pand most commands fail. - The script's own location is not
pwd.pwdshows where you are when the script runs, not where the script file lives; usedirname "${BASH_SOURCE[0]}"for that (seedirname). - Prompts:
\wand\WinPS1show$PWD, with~for your home directory.