Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · navigation

pwd

where am I

pwd prints the working directory: the one place every relative path is measured from. It is the smallest command in the shell and the first one to run when a script or a copy lands somewhere you did not expect.

Every relative path is relative to this directory — so know it before you type one.

Prints
Working directory
always an absolute path
Stands for
Print working directory
no arguments needed
Also held in
$PWD
the shell keeps it updated
Needs root
Never
it only reads

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashshell builtin
$ pwd
1/home/user/projects/netflow
$ cd /var/www/current
$ pwd
2/var/www/current
$ pwd -P
3/var/www/releases/2026-09-30
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The path starts at the root

The leading slash is the top of the filesystem. Read left to right, each name is a directory inside the one before it.

2
This is the logical path

The shell reports the names you travelled through. "current" is a symbolic link, and pwd shows it as you typed it.

3
-P shows where you physically are

With the link resolved, the real directory is a dated release folder. The two answers differ only when a symlink is in the path.

Switches

A switch changes how the command behaves. These are the ones used day to day; man pwd lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-L
Logical: print the path as you walked it, symbolic links included. This is the default.
-P
Physical: resolve every symbolic link and print where you really are on disk.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

echo $PWD

The same answer from the shell variable — the form to use inside scripts.

pwd -P

Resolves every symbolic link and prints the physical directory.

cd "$(dirname "$0")" && pwd

Inside a script: move to the script's own folder and confirm it, so relative paths behave.

echo $OLDPWD

The directory you were in before the last cd.

In cybersecurity

A command does what it does wherever the shell happens to be. Most accidents with destructive commands are a correct command run in the wrong directory.

Check before deleting

Run pwd before any rm or mv that uses a relative path or a wildcard. It costs one second.

Symlinked directories

A logical path can hide that you are really inside another filesystem or another user's tree. -P shows the truth.

Scripts and cron

A scheduled job does not start where you tested it. Set the directory explicitly rather than assuming it.

Filed under

Navigation

Read alongside