pwd Command in Linux



The pwd command in Linux displays the full path of the current working directory. Folders are separated by / (slash). The first / is the main folder (root), and the last one is the current folder. It helps confirm the exact location in the filesystem. It prevents mistakes, is useful in scripts, and can show the real location if links are used.

Table of Contents

Here is a comprehensive guide to the options available with the pwd command −

Syntax of pwd Command

The syntax of the pwd command in Linux is as follows −

pwd [options]

In the above syntax, the [options] field is used to specify various options to modify the output behavior.

pwd Command Options

The options of the Linux pwd command are listed below −

Flag / Option Description
-L, --logical Shows the path stored in the PWD environment variable, even if it includes symbolic links.
-P, --physical Displays the actual directory path by resolving all symbolic links.
--help Displays help information and exits.
--version Shows version details and exits.

Examples pwd Command in Linux

This section explains how to use the pwd command in Linux with examples −

  • Displaying Path Current Working Directory
  • Displaying the Logical Path of the Current Working Directory
  • Displaying the Physical Path of the Current Working Directory
  • Displaying Usage Help

Displaying Path of Current Working Directory

To display the current working directory in Linux, use the following command −

pwd
pwd Command in Linux 1

The output will show the full path of the current directory.

Displaying the Logical Path of the Current Working Directory

A logical path is the directory path as navigated, including symbolic links, without resolving them to their actual locations. To display the logical path of a directory, use the -L or --logical option with the pwd command −

pwd -L
pwd Command in Linux 2

A symbolic link is a shortcut that points to a file or directory without duplicating its content. This is the default behavior of pwd, but it may vary depending on the system and shell configuration.

Displaying the Physical Path of the Current Working Directory

A physical path is the actual directory path on the filesystem, with all symbolic links resolved. To display the physical path of a symbolic link, use the -P or --physical option −

pwd -P
pwd Command in Linux 3

Displaying Usage Help

To display the usage help of the pwd command, use the --help option −

pwd --help

Conclusion

The pwd command in Linux displays the full path of the current working directory, helping to confirm location and avoid mistakes. It supports options like -L for showing the logical path and -P for the physical path, resolving symbolic links.

The command is useful in scripts and when navigating directories. Additional options include --help for usage details and --version for version information.

In this tutorial, we explained the pwd command, its syntax, options, and usage in Linux with examples.

Advertisements