Every path in Linux starts somewhere, and the shell is always standing in exactly one spot. The pwd command — print working directory — tells you that spot: the absolute path of the directory you are in right now.
Basic usage #
$ pwd
/home/ana/projects/aospix
That is the whole command. It takes no arguments you normally care about, and it always prints one line: where you are, starting from the root /.
Why it matters #
Most mistakes in a terminal are location mistakes. A delete aimed at the wrong directory, an empty listing, a build script that cannot find a file — the cause is often that you were one level off. Running pwd before a destructive or unfamiliar operation is the cheapest insurance in the shell.
The shell also keeps the same value in the PWD environment variable, so scripts can read it without spawning a process:
#!/usr/bin/env bash
echo "working from $PWD"
mkdir -p "$PWD/output"
Symlinks: -L vs -P #
If part of your path is a symbolic link, pwd has two answers:
$ pwd
/home/ana/work
$ pwd -P
/home/ana/projects/aospix/work
pwd(logical, the default) keeps the path as you typed it, symlinks included.pwd -P(physical) resolves every symlink and shows the real location.
| Flag | Behaviour |
|---|---|
| (none) | Print the logical path, the default |
-L | Same as the default, kept for clarity in scripts |
-P | Resolve all symlinks, print the physical path |
Once you know where you are, the next step is looking around: ls lists what is next to you. Both are part of the terminal notes series on aospix.
