Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Syntax of `pwd` command in Linux
Implementations of pwd Command
Example of pwd command
PWD Options and their Explanation
Importance of pwd in Navigating Through the Linux Filesystem
Real-world Applications of pwd
Common Issues and Solutions
Best Practices
Frequently Asked Questions
What is pwd Command in Linux?
How do I use pwd?
What is the pwd command in C?
What is the pwd command in Linux Bash?
Last Updated: Mar 27, 2024

pwd command in linux

Author Riya Singh
0 upvote


pwd stands for Print Working Directory. It's a command used in Unix and Unix-like operating systems to output the current directory's full path name to the terminal. Here's how you could use it:

Copy code
$ pwd


The pwd command is fundamental for users to navigate and understand the directory structure they are working within, which is crucial for executing other commands accurately.

Syntax of `pwd` command in Linux

The syntax of pwd command in Linux:

pwd [OPTION]



  • -L: Display the logical current working directory.
  • -P: Display the physical current working directory (default).
  • --help: Display help information.
  • --version: Display version information.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Implementations of pwd Command

These are the implementations of pwd command:

1. Basic Usage:



2. Display Logical Path:

pwd -L


3. Display Physical Path:

pwd -P


4. Help Information:

pwd --help


5. Version Information:

pwd --version

Example of pwd command

# Navigate to a directory
$ cd /home/user/Documents

# Display the current working directory
$ pwd

# Create a symbolic link to the directory
$ ln -s /home/user/Documents /home/user/LinkToDocuments

# Display the logical path
$ pwd -L

# Display the physical path
$ pwd -P

# Move to the symbolic link directory
$ cd /home/user/LinkToDocuments

# Display the current working directory after moving through the symbolic link
$ pwd


In this example, the cd command changes the directory to /home/user/Documents. The pwd command displays the logical and physical paths of the current working directory. A symbolic link (LinkToDocuments) to the original directory is created. The logical and physical paths are displayed again. Moving through the symbolic link (cd /home/user/LinkToDocuments), the pwd command shows the updated current working directory.

PWD Options and their Explanation

The pwd command in Linux comes with a few options that provide flexibility in displaying the current working directory. Here are the primary options:

Option Description Example
No Option Displays the current working directory (physical path by default). pwd
-L Displays the logical current working directory, considering symbolic links. pwd -L
-P Displays the physical current working directory, ignoring symbolic links. pwd -P
--help Provides information on using the pwd command and its options. pwd --help
--version Displays version information about the pwd command. pwd --version

Importance of pwd in Navigating Through the Linux Filesystem

When working in a Linux environment, the directory structure forms a hierarchical tree, and it's essential to know your exact location within this hierarchy. Here's an illustrative example:

$ cd /var/www/html
$ cd ../../etc/apache2
$ pwd

In this scenario, a user navigates to the Apache configuration directory. Due to the relative directory changes with the cd (change directory) command, the user might lose track of their exact location within the filesystem. Executing the pwd command reaffirms the user's current directory, providing a clear understanding of their location within the directory hierarchy.

Real-world Applications of pwd

Scripting and System Administration

The pwd command is indispensable in various scenarios, particularly in scripting and system administration tasks. For instance, scripts often require the absolute path of a particular directory to function correctly. Here's an example in a shell script:


# Get the current directory


# Print the current directory

echo "The current directory is: $current_dir"

In this script, pwd is used to capture the current directory, which is then printed to the terminal. Such usage is common in scripts that need to operate relative to their current location in the filesystem.

Common Issues and Solutions

Incorrect Path due to Symbolic Links

A common issue arises when navigating through symbolic links; users might get confused with the output of pwd if they are unaware of the -L and -P options. Understanding the difference between logical and physical paths, as demonstrated in the examples above, is the solution to this common issue.

# Potential confusion without understanding the -L and -P options

$ ln -s /var/www/html link_to_html
$ cd link_to_html
$ pwd   # This will behave as pwd -L
$ pwd -P

By using the appropriate options with pwd, users can accurately determine their actual location within the filesystem, avoiding potential confusion when symbolic links are in play.

Best Practices

Effective Usage for Navigating and Scripting

The pwd command is a straightforward yet potent tool for navigating through the filesystem and scripting. Here are some best practices:

Absolute Paths: When scripting, it's often safer to work with absolute paths. Using pwd to ascertain and utilize absolute paths can help avoid common pitfalls associated with relative paths.


# Get the absolute path of the current directory


# Use the absolute path in the script

cat "$abs_path/file.txt"

Checking Directory Existence: Before proceeding with operations that depend on the current directory, it's wise to ensure the directory exists.


# Check if the current directory exists
if [[ -d $(pwd) ]]; then
    echo "Directory exists."
    echo "Directory does not exist."

Frequently Asked Questions

What is pwd Command in Linux?

The pwd command in Linux displays the present working directory, showing the current directory's full path.

How do I use pwd?

If you enter pwd in the terminal, it outputs the current directory's full path.

What is the pwd command in C?

In C programming, there's no direct pwd command. The <unistd.h> library's getcwd function is used for similar functionality.

What is the pwd command in Linux Bash?

In Linux Bash, pwd outputs the full path of the current working directory when entered in the terminal.


We've traversed the breadth of the pwd command, elucidating its syntax, usage, and importance in navigating the Linux filesystem. From basic usage to advanced scenarios like interacting with symbolic links, pwd proves to be an indispensable tool. Its utility in scripting and system administration tasks further underscores its significance.

Recommended Reads: Features of linux operating system

We also touched on common issues and how to resolve them, empowering you with the knowledge to navigate the filesystem adeptly. The discussion on best practices and the answers to frequently asked questions aim to provide a holistic understanding of the pwd command.

You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSADBMSCompetitive ProgrammingPythonJavaJavaScript, etc. 

Also, check out some of the Guided Paths on topics such as Data Structure and AlgorithmsCompetitive ProgrammingOperating SystemsComputer Networks, DBMSSystem Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.

Previous article
How to List All Group in Linux
Next article
xxd Command in Linux
Live masterclass