pwd Command in Linux

Learn via video courses
Topics Covered

Overview

The PWD command in Linux stands for 'print working directory.' It is used to display the current working directory on the screen. In this article, we will go through the syntax, options, example usages, tips, and advanced usages of the PWD command in Linux.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Linux pwd Command Syntax

The syntax for the pwd command is as follows:

Where:

  • [OPTION]: This is an optional parameter that determines the behavior of the command. If not specified, it displays the physical current working directory.
  • -L: This option displays the logical current working directory.
  • -P: This option displays the physical current working directory, which is the default behavior of the command.

pwd Command Options:

  • -L: Display the logical current working directory
  • -P: Display the physical current working directory (default behavior)

Example Usages

  • Display the physical current working directory:

    Output:

    Explanation: In this example, the PWD command is used without any options. It displays the physical current working directory, which is '/home/user/Documents'.

  • Display the logical current working directory:

    Output:

    Explanation: In this example, the PWD command is used with the '-L' option. It displays the logical current working directory, which is also '/home/user/Documents' in this case.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Tips

  • The PWD command is a basic command and does not require any special permissions to be executed.

  • The output of the PWD command is the current working directory, which is useful when navigating the file system.

Advanced Use Cases of pwd Command in Linux

  • Use the PWD command in a script to obtain the current working directory:

    Explanation: This command is used to assign the current working directory to a variable 'current_dir' which can be used later in a script. The output of the PWD command is stored in the variable without being displayed on the screen.

  • Redirect the output of the PWD command to a file:

    Explanation: This command is used to redirect the output of the PWD command to a file called 'current_directory.txt'. The file will contain the current working directory.

  • Use the PWD command in a pipeline:

    Explanation: This command is used to list the files in the current working directory using the 'ls' command. The output of the PWD command is used as an argument to the 'ls' command through the use of '$(pwd)'

Conclusion

  • The PWD command is a useful tool for displaying the current working directory in Linux.

  • The command has two options: '-L' to display the logical current working directory and '-P' to display the physical current working directory.

  • The output of the command can be used in scripts and pipelines to obtain and use the current working directory.

  • Remember that the PWD command is a basic command that does not require any special permissions to execute.

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more