📖 How to Get & View Current Directory in Linux
Methods and commands to determine your current working folder in Linux bash, zsh, and shell scripts.
1. Using the pwd Command
The simplest and most common way to display the current directory is the pwd (Print Working Directory) utility:
$ pwd
/var/www/rapidtables-online
/var/www/rapidtables-online
2. Using the $PWD Environment Variable
Linux shells maintain an environment variable named $PWD that always holds the current path:
$ echo $PWD
/home/ubuntu/projects
/home/ubuntu/projects
3. Getting Script Directory in Bash Scripts
When writing bash scripts, you often need the directory where the script itself lives, regardless of where it is executed from:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
echo "Script is running in: $SCRIPT_DIR"
echo "Script is running in: $SCRIPT_DIR"
4. Logical vs Physical Path (Symlinks)
If you navigated into a directory via a symbolic link, pwd by default outputs the logical path. To see the true physical disk path, use -P:
$ pwd
/var/www/site
$ pwd -P
/mnt/storage/sites/rapidtables
/var/www/site
$ pwd -P
/mnt/storage/sites/rapidtables