Navigation and files

Command pwd

Show current directory

Linux · Bash examples · commands run on the selected server

When to use pwd

Use pwd to confirm the directory in which a shell command will operate. This is especially useful after reconnecting to a server, switching users or navigating through symbolic links.

Syntax

pwd [PARAMETERS]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-L
Logical path taking into account symbolic links.
-P
Physical path without symbolic links.

Usage examples

Show working directory

pwd

The shell normally prints its logical working directory, which may retain symbolic-link components.

Show physical path

pwd -P

Physical mode resolves directory symlinks and prints the underlying location.

Save path in variable

workdir=$(pwd -P)

The physical path is captured in a shell variable for later use; quote the variable when expanding it.

Notes and limitations

  • Typically available as a shell builtin; individual utility may differ in details.
  • The current directory is specific to a specific process or session.

Common questions and troubleshooting

Why do pwd and pwd -P differ?

The shell can remember the logical path used to enter a symlink. Physical mode reports the resolved directory instead.

Can I assume a new SSH session starts here?

No. A new login normally starts in the configured login directory. Check pwd after connecting before running relative-path operations.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man pwd.