Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Run pwd in the terminal. It prints the absolute path of your current working directory, such as /home/alex/projects. For a path that resolves symbolic links, use pwd -P; to retain a logical path that includes symlinks, use pwd -L.
Check the current directory with pwd
A terminal has a current working directory: the location from which relative paths are interpreted. For example, notes.txt refers to a file in that directory, while ../Downloads refers to a directory one level above it. The POSIX specification defines the working directory as the starting point for resolving relative pathnames (POSIX getcwd).
- Enter
pwdand press Enter. - Read the absolute pathname printed by the command.
$ pwd
/home/alex/projects
On a conventional Linux filesystem, an absolute path starts with /. The command reports your location; it does not change it. The pwd utility is specified to write the absolute pathname of the current working directory (POSIX pwd).
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCurrent directory, home directory, and root
- Current directory: The directory the shell is currently using to resolve relative paths.
- Home directory: Your personal starting directory, commonly represented by
~. - Root directory: The filesystem’s top-level directory, written
/. - Directory contents:
lslists entries in a directory; it does not reliably print the current directory’s path.
Confirm your location after navigating
Use pwd after a cd command to verify where you landed. For instance, if your home directory is /home/alex, this sequence moves into Documents, returns to the parent, then goes back home:
#1 Best Overall
cd Documents
pwd
cd ..
pwd
cd ~
pwd
cd Documents uses a relative path; cd /home/alex/Documents uses an absolute one. cd .. moves to the parent directory, and cd ~ moves to your home directory. In common POSIX shells, running cd with no argument also normally returns home. To test a location directly, run cd /tmp followed by pwd; the result should be /tmp. cd - is a convenient shell command to return to the previous directory, not a way to display the current one.
Choose a logical or physical path
A symbolic link can give one directory more than one pathname. Suppose /tmp/pwd-demo/link is a symlink to /tmp/pwd-demo/real. After you enter through the link, the logical and physical path can differ:
mkdir -p /tmp/pwd-demo/real
ln -s /tmp/pwd-demo/real /tmp/pwd-demo/link
cd /tmp/pwd-demo/link
pwd -L
pwd -P
Possible output:
/tmp/pwd-demo/link
/tmp/pwd-demo/real
pwd -Lasks for the logical path, preserving a symlink component when the shell’s path information is valid.pwd -Pasks for the physical path, resolving symbolic links.
Use pwd -L when the path a user navigated through matters. Use pwd -P when you need the underlying filesystem path, for example while checking symlinks or mounts. Neither spelling is inherently more correct; they can name the same directory. GNU Coreutils documents these options and notes that shell built-ins or aliases can affect an unqualified interactive pwd (GNU Coreutils: pwd invocation). Plain pwd is enough for ordinary use, but its exact default can depend on the shell or implementation.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use the current directory in a script
In common shells, $PWD holds a shell-maintained path for the current directory. You can print it with:
printf '%sn' "$PWD"
For a script that needs the physical path and should handle failure, capture pwd -P and check its status:
#!/usr/bin/env bash
if current_dir=$(pwd -P); then
printf 'Current directory: %sn' "$current_dir"
else
printf 'Unable to determine the current directoryn' >&2
exit 1
fi
Quote path variables, as in "$current_dir", so spaces and shell metacharacters are not split or treated specially. GNU documents that pwd returns status 0 on success and nonzero on failure (GNU Coreutils: pwd invocation).
Do not confuse the working directory with the script’s location
pwd inside a script reports the process’s working directory—the directory from which the script was launched, or to which it later changed. It does not automatically report the directory containing the script file. If a script at /home/alex/bin/backup.sh is launched while the shell is in /home/alex, its working directory can be /home/alex.
Recommended Free Tools
When to use $PWD or command substitution
printf '%sn' "$PWD" is convenient in common interactive shells, but the variable can be unset or altered in unusual environments and may preserve a logical symlink path. For a script that requires a physical path, use pwd -P; when the result matters, check the command’s exit status. Command substitution such as current_dir=$(pwd) removes trailing newline characters, which is ordinarily immaterial for Linux paths. Keep the captured value quoted when using it.
Other ways to display or verify the path
printf '%sn' "$PWD"prints the shell-maintained variable; it is generally preferable toechoin scripts because its behavior is more predictable for arbitrary text.command pwdbypasses shell aliases and functions, though it may still invoke a shell built-in.env pwdinvokes an external command and can avoid a shell alias or built-in; GNU documents it as a way to bypass those overrides (GNU Coreutils: pwd invocation).realpath .canonicalizes the pathname supplied as an argument. It can resolve the physical path represented by., butpwd -Pis the direct command for the physical current working directory.realpathmay not be installed in minimal environments.
Do not use ls as a substitute: it lists directory contents rather than identifying the absolute path.
Rank #4
Why the prompt may not be enough
A prompt can show the full path, shorten it (often using ~ for the home directory), show only the last directory name, or omit the path. Run pwd if it is ambiguous. In Bash, w displays the working directory with the home directory abbreviated as ~, while W displays only its basename. For example, a temporary Bash prompt that includes the path is PS1='u@h:w$ ' (Bash manual).
Graphical file managers
In a graphical file manager, look for an address or location bar, a breadcrumb bar, or a mode that lets you enter a full location. The exact control varies by desktop and application; in a terminal, pwd is the broadly portable check.
Troubleshoot confusing results
The output differs between pwd, $PWD, and pwd -P
A symlink can make a logical path such as /srv/www differ from its physical target, such as /data/www. Also, an interactive shell may implement pwd as a built-in or provide an alias or function. If you need a specific interpretation, request -L or -P; use env pwd to invoke an external implementation when avoiding a shell override matters.
Best Value
The prompt shows only a short name
Prompts are configurable and may abbreviate or hide the path. Enter pwd rather than inferring the full location from the prompt.
The directory was deleted or cannot be accessed
A process can sometimes remain in a directory after it has been removed or renamed. Depending on the shell, filesystem, and implementation, pwd may fail or be unable to resolve it; there is no single error message to expect. Move to a directory that exists and check again:
cd /
pwd
You can use cd ~ instead if your home directory is accessible. A script should treat a nonzero result from pwd as failure rather than assuming it obtained a usable path.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The path contains spaces or unusual characters
pwd prints spaces as part of the path. When reusing the output, keep it in a quoted variable:
current_dir=$(pwd)
cd "$current_dir"
Unquoted expansion such as cd $current_dir can split a path at spaces and interpret shell metacharacters. For Bash-only shell-escaped display, use printf '%qn' "$PWD"; for portable scripts, preserve the path in a quoted variable instead of manually escaping it.
You are in an SSH session or container
pwd reports the working directory in the environment where it runs. For example, ssh [email protected] pwd checks the remote session, while docker exec <container> pwd checks inside the container. Neither necessarily reports the local terminal’s directory.
Quick Recap
Quick reference
| What you need | Command | What it tells you |
|---|---|---|
| See the current directory | pwd |
Absolute current path |
| Preserve the logical path | pwd -L |
Path may retain symlink components |
| Resolve symbolic links | pwd -P |
Physical path |
| Print the shell variable | printf '%sn' "$PWD" |
Shell-maintained path, if available |
| Return to the previous directory | cd - |
Changes directories; does not print the path by itself |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →

