Where to start First steps track · 15 stages
Linux Labs

pwd — the working directory

3 min Ubuntu 24.04; Bash builtin pwd, Bash 5.2.21; not external GNU pwd

The Bash builtin prints the logical or physical path of the current directory.

Cheat sheet

5 commands Printable version
  • pwd current path
  • pwd -L logical path
  • pwd -P physical path
  • type pwd command implementation
  • help pwd Bash help

Overview

pwd prints the shell’s current working directory. This page covers the Bash builtin selected by a plain pwd invocation in the golden snapshot.

A logical path retains symbolic-link components used to reach the directory. A physical path resolves them. Two different path strings can therefore refer to the same directory. Neither result lists files or necessarily identifies the home directory.

Options

2

Ordinary Bash defaults to -L, using PWD when it identifies the current directory. -P requests a physical path. Assigning PWD does not change directories; cd does that.

The external GNU pwd has its own option set. Its help/version options and defaults are not part of this builtin reference; an external-command snapshot was not supplied.

Option What it does Example
-L Print the logical path, retaining symbolic-link components when PWD is valid. pwd -L
-P Print the physical path with symbolic links resolved. pwd -P

Nothing found. Try a shorter query.

Recipes

3

Check location before file operations

Inspect location and contents separately: they answer different questions.

bash
pwd
ls

Resolve a physical path

Compare both results after entering through an existing symbolic link. Identical results are also normal.

bash
pwd -L
pwd -P

Identify which pwd is selected

Bash may select a builtin, function, or alias. Identifying it explains differences in supported options.

bash
type -a pwd
help pwd

Troubleshooting

3

pwd: --: invalid option

The snapshot shows this message for pwd --version: the builtin was selected. Read its help through the shell.

bash
help pwd

The path differs from what you expected

A symbolic link can explain the difference without a different directory being involved. Compare logical and physical results.

bash
pwd -L
pwd -P

The current directory was removed

If the directory path cannot be recovered, change to an existing directory and check again. This does not restore deleted files.

bash
cd /home/student
pwd

Danger zone

pwd does not modify files. A stale or unchecked path is not sufficient justification for deletion: inspect the actual target before changing it. The directory / is not the root account.

Terms

1
working directory
The directory from which a process resolves relative paths. In a shell, pwd prints it and cd changes it; a child process inherits it from its parent. Also appears in: cd, Container images, Dockerfile, /proc: processes and the kernel as files and 1 more

See also

  • cd — changing directory.

  • links — symbolic links and their targets.

  • files-basics — navigation and file operations.

  • bash — shell builtins.

Loading…