How to display the current working directory in the Linux system?

To print the current working directory, we use the pwd command in the Linux system.

pwd (print working directory) − The pwd command is used to display the name of the current working directory in the Linux system using the terminal. This is a shell builtin command that is available in most Unix shells such as Bourne shell, ash, bash, ksh, and zsh.

Syntax

The general syntax of the pwd command is as follows −

pwd [-LP]

A brief description of options available in the pwd command.

Option Description
-L (logical) Display the value of $PWD if it names the current working directory
-P (physical) Display the physical directory, without any symbolic links
--help Display help message and exit

By default, the pwd works as if -L option was specified.

Exit Status

The pwd command returns true unless an invalid option is supplied or the current directory could not be read.

Examples

Basic Usage

To display the current working directory, we use the pwd command in the Linux/Unix system as shown below.

vikash@tutorialspoint:~ pwd
/home/vikash

Using the -P Option

To display the physical directory instead of symbolic links or soft links, we use -P option with the pwd command in the Linux/Unix system as shown below.

vikash@tutorialspoint:~ pwd -P
/home/vikash

Getting Help

To display more information about the pwd command we use --help option with the pwd command as shown below.

vikash@tutorialspoint:~ pwd --help
pwd: pwd [-LP]
    Print the name of the current working directory.
    
    Options:
      -L        print the value of $PWD if it names the current working directory
      -P        print the physical directory, without any symbolic links
    
    By default, `pwd' behaves as if `-L' were specified.
    
    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.

Difference Between -L and -P Options

When working with symbolic links, the -L and -P options produce different results −

# Create a symbolic link
ln -s /var/log mylog
cd mylog

# Using -L (default behavior)
pwd -L
/home/vikash/mylog
# Using -P (physical path)
pwd -P
/var/log

Common Use Cases

  • Shell scripting − Use pwd to store the current directory before changing locations

  • Path verification − Confirm your location in the filesystem

  • Debugging scripts − Display current directory for troubleshooting

  • Environment variables − Set variables based on current working directory

Conclusion

The pwd command is an essential Linux utility for displaying the current working directory. It supports logical and physical path display options, making it useful for both interactive sessions and shell scripting. Understanding the difference between -L and -P options is particularly important when working with symbolic links.

Updated on: 2026-03-17T09:01:38+05:30

38K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements