pwd – Print Working Directory

The pwd command prints the current working directory you are in.

Though it might seem trivial, pwd is often useful in shell scripts and terminal sessions to confirm your current location in the filesystem.


Syntax

pwd [OPTIONS]

Options

Option Description
-L Print the logical current directory (do not resolve symbolic links), even if physical mode is set in the shell
-P Print the physical directory by resolving symbolic links
--help Display help information about the pwd command

Note: Bash shell options are case-sensitive, while Fish shell accepts lowercase options.


Practical Examples

1. Display the current directory

pwd

Output example:

/home/user/

2. Use with cd to navigate and verify

user@laptop:~$ cd Folder
user@laptop:~$ pwd
/home/user/Folder

3. Combine with other commands

ls -l $(pwd)

Lists the contents of the current directory with detailed information.


4. Use in a logging script

#!/bin/bash
echo "Running script in directory: $(pwd)"
# Other commands...

5. Difference between pwd and echo $PWD

pwd
echo $PWD
  • Both typically show the same path.
  • pwd queries the shell for the current directory.
  • $PWD is an environment variable holding the last known directory.
  • When symbolic links are involved, outputs can differ:
cd /tmp
ln -s /etc etc_link
cd etc_link

pwd          # shows: /tmp/etc_link  (logical path)
echo $PWD    # shows: /tmp/etc_link
/bin/pwd     # shows: /etc           (physical path)

Tips

  • Use pwd -P to get the actual physical directory path, resolving symlinks.
  • Use pwd -L (default) to get the logical path, which might include symlinks.
  • In scripts, pwd helps confirm the script’s execution directory.

See Also

  • cd – change directory
  • ls – list directory contents
  • Environment variables like $PWD and $HOME

Summary

pwd is a simple but essential command to identify the current directory. Its options allow you to control whether symbolic links are resolved or not, making it handy for both interactive and scripted use.