October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Linux pwd Command: 15 Practical Examples for Finding and Using Your Current Directory

Use Linux’s pwd command to print your current directory, choose logical or symlink-resolved paths, and save or check the output in shell commands.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

pwd prints the current working directory; it does not change it. Use pwd -L to request a logical path that may retain symbolic-link names, or pwd -P to request the physical, symlink-resolved path. Which implementation runs—a shell builtin or an external utility—can affect defaults, so explicit options are useful when the distinction matters.

Choose the path format you need

A logical path reflects the route represented by the shell’s current-directory state and can preserve a symbolic-link name. A physical path resolves symbolic links to the directory’s actual path components.

As an Amazon Associate I earn from qualifying purchases.

  • Use -L when the symlinked route is meaningful to your workflow or to the person reading the output.
  • Use -P when you need the resolved filesystem path.

GNU pwd uses a valid absolute PWD value for logical output when that value contains no . or .. components. If it is unsuitable, GNU falls back to physical handling. GNU’s default is physical unless POSIXLY_CORRECT is set. Bash documents its builtin’s default as physical unless set -o physical is enabled. When both -L and -P are supplied to GNU pwd, the last option wins. See the GNU Coreutils pwd documentation and the Bash builtin reference.

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

15 practical pwd examples

Run these in a shell. Examples that change directories affect the current shell session; run them separately if you do not want one example’s location to affect the next.

  1. Print the current directory

    pwd

    Prints the current working directory using the behavior of the command implementation that runs.

  2. Request a logical path

    pwd -L

    Asks for the logical path, which can retain symbolic-link names.

  3. Request a physical path

    pwd -P

    Asks for the path with symbolic links resolved.

  4. Use GNU’s long option for logical output

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

    pwd --physical
  6. Put physical mode last

    pwd -L -P

    For GNU pwd, the final mode option determines the requested mode, so this asks for physical output.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  7. Put logical mode last

    pwd -P -L

    For GNU pwd, this asks for logical output.

  8. Change to /tmp, then print the location

    cd /tmp
    pwd

    The first command changes the shell’s current directory; the second prints it.

  9. Move to the parent directory

    cd ..
    pwd

    cd .. moves to the parent of the current directory, and pwd prints the resulting location.

  10. Go to your home directory

    cd ~
    pwd

    The shell expands ~ to your home directory before changing location.

  11. Invoke Bash’s builtin explicitly in physical mode

    builtin pwd -P

    In Bash, builtin selects the shell builtin rather than an external command.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  12. Invoke Bash’s builtin explicitly in logical mode

    builtin pwd -L
  13. Run the external utility through env

    env pwd -P

    GNU documents this form as a way to avoid shell aliases and builtin functions when invoking the external utility.

  14. Save the output in a variable

    current_dir=$(pwd)
    printf '%sn' "$current_dir"

    Command substitution captures the printed path for later use. Quoting the variable keeps its value together if the path contains spaces.

  15. Check whether printing the directory succeeds

    if pwd >/dev/null; then
      printf '%sn' 'Current directory is available'
    fi

    pwd returns status zero on success and nonzero on failure; the conditional runs its body only when the command succeeds.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Know which pwd implementation is running

pwd may resolve to a shell builtin or an external utility. Bash includes a pwd builtin. GNU notes that an unqualified invocation can be affected by shell aliases or functions; in GNU environments, env pwd ... invokes the external utility instead. Use builtin pwd ... in Bash when you specifically want its builtin, or env pwd ... when you want to bypass shell aliases and functions for the external command. Explicitly choosing -L or -P makes your intended path style clearer, but defaults and supported options still depend on the implementation.

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

GNU’s documented options and behavior are in its pwd invocation reference; Bash’s builtin behavior is described in its 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.