The “pwd” Command in Linux [4 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The pwd command is one of the most widely used commands available. It stands for print working directory. Most users use this command for their day-to-day navigation. In this article, you will learn about the functionality of the pwd command in Linux and some practical examples.

A. Description

pwd command displays the Absolute path of the current directory. This command shows where the Terminal currently is in detail and will help you when you are lost inside some unknown directory.

The command pwd also has an environment variable. You can access this variable by using $PWD in the Terminal.

B. Syntax

You can type the man command in the Terminal like man pwd and find the syntax and options available by the pwd command. The synopsis of the command pwd is very simple as you can only apply options, and there are not many of these options for use.

pwd [OPTION]...

Note: You can only use options with pwd command, as square brackets enclose OPTION. There are three dots after the OPTION which means multiple options can be used simultaneously.

C. Options

In the man page of the pwd command, You can find some options that are quite small in number.

Here are all the OPTIONS available for the pwd command. You can check the man page for pwd command.

man pwd

Useful Options

  • -L Uses PWD variable from the environment. If it contains a symlink, this command will then process that symlink.
  • -P Avoids any type of symlinks and shows only the current directory path.
  • –help Provides help on the available options for the pwd command.
Note: By default, pwd command runs with the -L option. Run the man pwd command to know more about this.

Practical Examples of the “pwd” Command in Linux

pwd command in Linux is one of the most frequently used commands for navigation. You will have to use this command often to navigate and find your current directory.

Example 1: Finding the Current Directory Using the “pwd” Command

You can view your current directory using the pwd command, and most of the time, you will use this command for this purpose. To do this, you have to follow the procedures below:

Steps to Follow >

❶ Open Terminal. By default, the Terminal will be opened in the Home directory.

Alternatively, You can open Terminal from the Menu or use a shortcut key CTRL + ALT + T.

❷ Type the following simple command in the command prompt.

pwd

❸ Now, Press the ENTER button.

Output >

You can see in the picture that I have found the Absolute path of the Home directory.

pwd command in linux to show absolute directory


Similar Readings


Example 2: Finding the Absolute Path of any Directory Using the “pwd” Command

You can use pwd command to find the Absolute Path of any directory. To do this you have to follow the procedures below:

Steps to Follow >

❶ Suppose you have a directory structure like the following.

folder structure

❷ You have opened your Terminal in the FF_3 folder. But you want to know about the Absolute path of the current directory. Again type the following simple command.

pwd

❸ Now, Press the ENTER button.

Output >

In the following picture, you can see that I have found the Absolute path of the FF_3 folder in the command prompt.

find absolute path of current directory

Example 3: Using the “pwd” Command on Symlink

Symbolic links are like shortcuts that lead to actual files or folders in another directory. pwd command by default, shows only the location of the symlink. But you can use another option to find the file location using the pwd command. To do this, you have to follow the procedures below:

Steps to Follow >

❶ Open Terminal in the Home directory.

❷ Now, we have to create a symbolic link. To do that, we have to use the ln command shown below.

ln -s Desktop/LinuxSimply/Folder_2/FF_3 Symblink

❸ Now, you need to change the directory of the pwd command by the following command.

cd Symblink

Then, you can use the following commands to view the current directory.

pwd
pwd -L

❹ After that, you can type the following command to view the difference.

pwd -P

❺ Finally, Press the ENTER button.

Output >

As you can see, pwd command and pwd -L command shows the same output, which is the location of the directory where the symbolic link is present.

But pwd -P command shows the Absolute path of the referenced directory. Here, it shows the path of the FF_3 directory.

pwd command for symblink

Note: By default, the pwd command uses the -L option. So, without using any option will give you the same result, which is the location of the symbolic link.

Similar Readings


Example 4: Finding the syntax Using the –help Option

Like most of the commands, pwd command also has a help option. To use this option, use the following procedure.

Steps to Follow >

❶ Open the Terminal.

❷ Type the following command in the command prompt.

pwd --help

❸ Press the ENTER button.

Output >

You will find the options available for the pwd command. Here, the default option of the pwd command is also mentioned.

help option for pwd command in linux

Conclusion

In this article, you have learned about using pwd command in Linux. You’ve also learned about the practicality of the command in day-to-day life. To show that, here are 4 practical examples of the pwd command. There are few syntax and options involved, but this command is easy to master. This command will certainly help you as an efficient and power user.


Similar Readings

Rate this post
Md. Rafsan Zani

Hello, I’m Md. Rafsan Zani. I have recently completed my Undergraduate from the Bangladesh University of Engineering and Technology (BUET). Currently, I’m pursuing higher studies abroad. I’m really interested in computer science and would like to learn a lot about the wonderful world of computers. Currently, I’m working as a Linux Content Developer Executive and find Linux really interesting. I certainly would like to learn more about Linux and implement them in my future studies. Read Full Bio

Leave a Comment