opscape

Files and directories · bash builtin

pwd

Print the full path of the current working directory.

pwd [-L|-P]

6 of 6 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: pwd(1)

pwd prints the absolute path of the directory you are in. Bash has a builtin pwd, which is what runs when you type it; coreutils also ships /usr/bin/pwd for programs that are not shells.

The only question pwd has to answer is what to do about symbolic links. pwd -L (the bash builtin's default) prints the path as you navigated it, links included, taken from $PWD. pwd -P resolves every link and prints the physical location. In scripts, "$PWD" is the same as $(pwd) without starting a command substitution.

Examples

Show where you are

pwd
explain
output
/home/dev/demo

Every example on this site starts in /home/dev/demo.

Check the directory after moving

cd data/../logs
pwd
output
/home/dev/demo/logs

pwd always prints a clean absolute path; the data/.. detour is gone.

Physical path through a symlink

Setup run before this example
ln -s src/lib lib-link
cd lib-link
pwd
pwd -P
output
/home/dev/demo/lib-link
/home/dev/demo/src/lib

pwd shows the path the way you got there, through the link. pwd -P resolves the link and shows where the directory really is.

The builtin versus /usr/bin/pwd

Setup run before this example
ln -s src/lib lib-link
cd lib-link
type pwd
/usr/bin/pwd
output
pwd is a shell builtin
/home/dev/demo/src/lib

type confirms pwd is a shell builtin, defaulting to -L. The coreutils program defaults to -P (unless POSIXLY_CORRECT is set), so it prints the resolved path.

Use $PWD in a script

cd src
echo "building in $PWD"
echo "came from $OLDPWD"
output
building in /home/dev/demo/src
came from /home/dev/demo

Bash keeps $PWD and $OLDPWD current after every cd, so scripts can use them directly instead of running $(pwd).

When the current directory has been deleted

mkdir gone && cd gone
rmdir ../gone
pwd
/usr/bin/pwd
outputexit 1
/home/dev/demo/gone
pwd: couldn't find directory entry in ‘..’ with matching i-node

The builtin still prints the remembered $PWD. /usr/bin/pwd has to work the path out on disk by walking up through .., finds no entry for the deleted directory and exits with 1. cd .. or plain cd gets you out.

Common pitfalls

  • $(pwd) in a script spawns a subshell for nothing; "$PWD" gives the same value.

  • If a script needs its own location rather than the caller's current directory, pwd is the wrong tool: use dirname "$(realpath "$0")" or bash's ${BASH_SOURCE[0]}.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • Both GNU and BSD pwd accept -L and -P. Shell builtins default to -L; the standalone GNU pwd program defaults to -P unless POSIXLY_CORRECT is set.

Options worth knowing

A selection, described in our own words. For the full list, see pwd(1).

OptionWhat it does
-L, --logicalPrint $PWD as navigated, symlinks included.
-P, --physicalResolve all symlinks and print the real path.

Related