Linux pwd Command: Print the Current Working Directory
pwd is a command that prints the path of the current working directory (Current Working Directory). It is used to check which directory you are in within the terminal or to verify the reference location for relative paths in shell scripts.
Generally, running it without options is sufficient, but when the path includes symbolic links, it is important to understand the difference between -L, which shows the logical path, and -P, which shows the actual filesystem path.
What is the pwd command?
pwd stands for print working directory. It prints the absolute path of the directory that the current shell or process is using as its working reference.
pwd
For example, if your current location is the user's project directory, it might output as follows.
/home/user/projects/web-app
The current working directory is the reference for interpreting relative paths. The same relative path, config/settings.ini, points to different files depending on which directory the command is executed from.
Basic Syntax and Usage
pwd [options]
Since it is not a command that takes other paths as arguments, it is usually run alone as follows.
pwd cd /var/log pwd
The second pwd will output /var/log if the move was successful. If cd fails, the current working directory does not change.
Difference between -L and -P
If the path to the current location contains symbolic links, the logical path and physical path may differ.
| Option | Action |
|---|---|
-L, --logical |
Uses the logical path remembered by the shell. The symbolic link names used during navigation may remain in the path. |
-P, --physical |
Outputs the physical directory path after resolving symbolic links. |
Checking logical path with -L
Assume that /srv/current is a symbolic link that points to the actual deployment directory.
cd /srv/current pwd -L
If the shell properly manages the logical location, the link path entered by the user can be preserved as follows.
/srv/current
Checking the actual path with -P
pwd -P
If /srv/current points to /srv/releases/2026-09, the physical path can be output as follows.
/srv/releases/2026-09
The -P option is useful when you want to check which directory the deployment link actually points to, or when you need a path that does not rely on the symbolic link name.
Shell built-in pwd and external pwd
Many shells, including Bash, provide pwd as a built-in command. The system may also have the external executable from GNU Coreutils installed.
type -a pwd command -V pwd
Depending on the environment, both the shell built-in command and the external executable may be displayed as follows.
pwd is a shell builtin pwd is /usr/bin/pwd
Reasons to use the shell built-in command
The shell directly manages its working directory and logical path when moving directories with cd. Therefore, the built-in pwd can output that information without starting a separate process.
-L and -P can generally be used with both built-in and external commands, but the detailed options may vary depending on the shell and operating system.
Explicitly executing external commands
To check the behavior of GNU Coreutils executables, you can specify the full path. The actual location may vary depending on the distribution.
/usr/bin/pwd /usr/bin/pwd -P
For scripts that require portability, it is better not to assume that a specific absolute path exists on all systems.
PWD and OLDPWD environment variables
The shell can manage the current location and the previous location as variables. The variable names are in uppercase, so they should be distinguished from the pwd command.
| Item | Meaning |
|---|---|
pwd |
A command that prints the current working directory. |
PWD |
The logical path of the current working directory remembered by the shell. |
OLDPWD |
Generally, the working directory just previously used. It is used in cd -. |
printf '%s\n' "$PWD" printf '%s\n' "$OLDPWD" pwd -L pwd -P
PWD is a shell variable, so if the user changes it arbitrarily or it becomes abnormal, it may not match the actual location. If the actual file system path is important, check it with pwd -P.
Using in shell scripts
Checking execution location
If the script is assumed to run in a specific directory, you can check the location before doing the work.
current_dir=$(pwd -P) || exit 1 printf 'Current working directory: %s\n' "$current_dir"
When using the result of command substitution, enclose the variable in double quotes to keep paths with spaces as a single word.
Distinguishing from script file location
What pwd outputs is not the directory where the script is stored, but the current working directory of the process that ran the script.
cd /tmp /opt/tools/backup.sh
In this case, pwd executed inside backup.sh usually outputs /tmp. If you need the script's own location, you need to separately consider the shell type, symbolic link handling, and the way the script is called.
Comparison of pwd and related commands
| Command | Purpose |
|---|---|
pwd |
Prints the path of the current working directory. |
cd |
Changes the working directory of the current shell. |
realpath |
Normalizes the specified file name or path and prints it as an absolute path. |
dirname |
Prints the part of a path string excluding the last component. |
readlink |
Checks the target string stored in a symbolic link. |
Common issues
Deleted or inaccessible current directory
If the current location or a parent directory is deleted or access permissions are changed by another process, pwd may not be able to determine the path and may produce an error. Move to an accessible parent directory and check again.
The path and output are different from what was expected
If you navigated through a symbolic link, the results of pwd -L and pwd -P may differ. It does not mean that either path is wrong; it shows two different perspectives: the logical name and the physical location.
The path changes in scripts
Cron, systemd, CI jobs, and containers can start programs in a working directory different from an interactive terminal. Before using relative paths, record the execution environment with pwd or use a clear absolute path and set the working directory.
FAQ
What does pwd stand for?
It stands for print working directory and prints the path of the current working directory.
Is pwd the same as echo "$PWD"?
In a normal shell state, similar logical paths may appear, but they do not behave the same. PWD is a shell variable, while pwd is a command that prints the current location, and pwd -P can get the physical path by resolving symbolic links.
Which should I use, pwd -L or pwd -P?
Use -L if you want to retain the path name that the user navigated, and use -P if you need the actual file system path with symbolic links resolved.
Does pwd output the location where the script is stored?
No. It outputs the current working directory of the process executing the script. The location of the script file and the current working directory may be different.









