pwd Command in Linux: Print the Current Working Directory

By 

Updated on

4 min read

Using the pwd command to print the current working directory in Linux

The pwd command stands for “print working directory.” When invoked, it prints the full path of the directory you are currently in.

This guide explains how to use the pwd command with practical examples.

What Is the Current Working Directory

The current working directory is the directory in which the user is currently working. Each time you interact with your command prompt, you are working within a directory.

By default, when you log into your Linux system, your current working directory is set to your home directory. To change the working directory, use the cd command.

For example, to change the current working directory to /tmp:

Terminal
cd /tmp

If you have a customized bash or zsh prompt, the path to the current working directory may be shown in the shell prompt:

output
user@host:/tmp#

pwd Command Syntax

The syntax for pwd is:

txt
pwd [OPTION]

pwd is a shell builtin in most modern shells such as Bash and Zsh. Its behavior is slightly different from the standalone pwd executable. You can use the type command to display all locations containing an executable named pwd:

Terminal
type -a pwd
output
pwd is a shell builtin
pwd is /usr/bin/pwd

The shell builtin takes priority over the standalone executable and is used whenever you type pwd. To use the standalone binary, type its full path as reported by type -a pwd on your system.

How to Find the Current Working Directory

To print the current working directory, run:

Terminal
pwd
output
/home/linuxize

In normal interactive shell usage, pwd and the PWD environment variable usually show the same directory, so the following command typically produces the same output:

Terminal
echo $PWD
output
/home/linuxize

The $PWD variable is useful in scripts when you need to store the current directory before changing to another one and return to it later. The shell also maintains $OLDPWD, which holds the path of the previous working directory.

pwd Options

pwd accepts two options:

  • -L (--logical) — Do not resolve symlinks. Print the path as navigated, which may include symlink names. This is the default behavior.
  • -P (--physical) — Resolve symlinks and print the actual physical path on the filesystem.

To illustrate the difference, create a directory and a symlink pointing to it:

Terminal
mkdir /tmp/directory
ln -s /tmp/directory /tmp/symlink

Navigate into the symlink and run pwd:

Terminal
cd /tmp/symlink
pwd
output
/tmp/symlink

The default -L behavior shows the path as navigated, including the symlink name. Now run pwd -P:

Terminal
pwd -P
output
/tmp/directory

The -P option resolves the symlink and prints the real path of the target directory.

Quick Reference

CommandDescription
pwdPrint the current working directory
pwd -LPrint the path as navigated (symlinks not resolved)
pwd -PPrint the physical path (symlinks resolved)
echo $PWDPrint the current directory via the environment variable
echo $OLDPWDPrint the previous working directory

FAQ

What is the difference between pwd -L and pwd -P? pwd -L prints the path as you navigated to it, preserving symlink names. pwd -P resolves all symlinks and prints the real filesystem path. If you navigated into a symlink directory, -L shows the symlink path and -P shows the actual target path.

What is the $PWD variable? $PWD is a shell environment variable that always holds the path of the current working directory. It is updated automatically by the shell whenever you change directories. It is equivalent to running pwd and is useful in scripts to capture or reference the current path.

What is $OLDPWD? $OLDPWD is a shell variable that stores the path of the previous working directory — the one you were in before the last cd command. Running cd - switches back to $OLDPWD.

Can I use pwd in a shell script? Yes. Using pwd or $PWD in a script is a common way to capture the directory from which the script was launched or to construct absolute paths relative to the current location.

Conclusion

The pwd command prints the full path of the current working directory. Use pwd -P when you need the physical path with all symlinks resolved, and pwd -L (the default) when you want the path as navigated.

If you have any questions, feel free to leave a comment below.

Tags

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page