Bash Print Directory
Use the pwd command to find out exactly where you are in the filesystem at any moment.
The pwd Command
pwd stands for 'print working directory'. It prints the absolute path of the directory the shell is currently sitting in, and it is usually the very first command you run when you feel lost inside a filesystem.
Every running process, including your shell, keeps track of a single current working directory. Commands that take relative file paths, like cat notes.txt, resolve them against this directory, which is why knowing your location matters.
Basic Usage
Printing Your Location
$ pwd
/home/alex- Confirm your location before running a destructive command like rm -rf
- Build absolute paths inside scripts using command substitution
- Debug unexpected behavior after a cd that did not go where you expected
- Check whether a symlinked directory is being resolved logically or physically
Logical vs. Physical Paths
$ cd /var/log/myapp
$ pwd
/var/log/myapp
$ pwd -P
/mnt/data/logs/myappUsing pwd in Scripts
Inside scripts, pwd is often combined with command substitution to capture the current path into a variable, which you can then reuse to build log messages, file paths, or backup destinations.
Capturing pwd Into a Variable
$ CURRENT=$(pwd)
$ echo "You are working in $CURRENT"
You are working in /home/alex/projects