Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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).

  1. Enter pwd and press Enter.
  2. 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).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Current 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: ls lists 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:

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 -L asks for the logical path, preserving a symlink component when the shell’s path information is valid.
  • pwd -P asks 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 to echo in scripts because its behavior is more predictable for arbitrary text.
  • command pwd bypasses shell aliases and functions, though it may still invoke a shell built-in.
  • env pwd invokes 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 ., but pwd -P is the direct command for the physical current working directory. realpath may not be installed in minimal environments.

Do not use ls as a substitute: it lists directory contents rather than identifying the absolute path.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.