Navigation basics

Linux commands: pwd

Learn how the Linux pwd command prints your current working directory, so you always know exactly where you are in the filesystem when you feel lost.

8 minute lesson

~~~

Every shell process has a current working directory. Relative paths start there, so the same command can affect different files depending on where you run it.

pwd

The output is an absolute path such as /Users/flavio/projects/site. Use it before a destructive command, after several cd operations, or when a script behaves differently in two terminals.

Compare absolute and relative paths:

pwd
ls notes.txt
ls "$(pwd)/notes.txt"

The last two commands identify the same file. Quoting $(pwd) matters because a directory name may contain spaces.

The shell also keeps the current path in $PWD:

printf '%s\n' "$PWD"

pwd -P resolves symbolic links and prints the physical path. Plain pwd may preserve the logical route you used to enter a symlinked directory. That distinction matters when debugging scripts that compare paths.

Try it: create a directory, enter it through a symbolic link, then compare pwd and pwd -P. The command works on Linux, macOS, WSL, and other Unix-like environments.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →