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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use pwd to print the absolute path of your current working directory. It does not change directories. Add -L to request a logical path that may retain symbolic-link names, or -P for a physical path with symbolic links resolved. Which result you get can depend on whether your shell runs its own pwd builtin or an external utility.

What does pwd do?

The name stands for “print working directory.” The command reports the directory the shell is currently using; it is useful for checking where you are before running commands or for saving the path for later use. GNU Coreutils describes it as printing “the name of the current directory.” GNU Coreutils: pwd invocation

To move to a different directory, use cd; pwd only displays the current location. The examples below use standard shell syntax and document the command’s behavior; they are not claims about testing in a particular Linux distribution.

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.

15 practical pwd examples

Print and choose a path format

  1. Print the current directory:

    pwd
  2. Request the logical path: -L may preserve symbolic-link names in the path.

    pwd -L
  3. Request the physical path: -P resolves symbolic links to the actual directory names.

    pwd -P
  4. Use GNU’s long option for logical output:

    pwd --logical
  5. Use GNU’s long option for physical output:

    pwd --physical
  6. Supply both modes, with physical last: for GNU pwd, the last of -L and -P wins.

    pwd -L -P
  7. Reverse the option order: logical mode is last, so GNU pwd uses it.

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

Change location, then check it

  1. Move to /tmp and print the new location:

    cd /tmp
    pwd
  2. Move to the parent directory and check: .. refers to the parent of the current directory.

    cd ..
    pwd
  3. Move to your home directory and print its current path:

    cd ~
    pwd

Choose the implementation or use the output

  1. Run Bash’s builtin explicitly in physical mode:

    builtin pwd -P
  2. Run Bash’s builtin in logical mode:

    builtin pwd -L
  3. Invoke the external command through env: GNU documents this form to avoid shell aliases and builtin functions.

    env pwd -P
  4. Store the output in a shell variable: command substitution captures the output for a later command.

    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.
    current_dir=$(pwd)
    printf '%sn' "$current_dir"
  5. Use the exit status in a conditional: success runs the message; a failure skips it.

    if pwd >/dev/null; then
      printf '%sn' 'Current directory is available'
    fi
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use pwd -L or pwd -P?

Choose based on whether the route used to reach the directory matters or whether you need the resolved filesystem path.

  • Use pwd -L when you want the logical path, which can preserve the name of a symbolic-link route. GNU pwd uses the PWD environment value only if it is a valid absolute path without . or .. components; otherwise, it falls back to physical handling.
  • Use pwd -P when you need the path with symbolic links resolved to actual directory names.

GNU pwd defaults to physical output unless POSIXLY_CORRECT is set. Bash documents its builtin’s default as physical unless set -o physical is enabled. Because defaults and behavior depend on the implementation, scripts that need a specific path format should state -L or -P explicitly. See the GNU Coreutils documentation and the Bash Reference Manual.

Is pwd a shell builtin or an external command?

It can be either. Bash provides pwd as a builtin, while GNU Coreutils also provides an external pwd utility. An unqualified pwd may therefore run a shell builtin, and shell aliases or functions can also affect what a command name invokes. In Bash, use builtin pwd to request the builtin; use env pwd to invoke the external utility without a shell alias or builtin function taking precedence.

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

What happens if pwd fails?

On success, pwd returns status zero; failure returns a nonzero status. Bash documents errors determining the directory and invalid options as cases that produce a nonzero return. You can use that status in a conditional, as in example 15. The Bash builtin’s documented behavior is in the Bourne Shell Builtins reference.

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.