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.
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.
Similar Readings
- The ācdā Command in Linux [6 Practical Examples]
- The ālsā Command in Linux [7+ Practical Examples]
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.
ā· 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.
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.
Similar Readings
- The āmvā Command in Linux [8 Practical Examples]
- The ācpā Command in Linux [6 Practical Examples]
- The ārmā Command in Linux [7 Practical Examples]
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.
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
- The ātouchā Command in Linux [8 Practical Examples]
- The āmkdirā Command in Linux [6+ Practical Examples]
- The ālocateā Command in Linux [7 Practical Examples]
- The āfindā Command in Linux [10+ Practical Examples]
- The āchmodā Command in Linux [6 Practical Examples]
- The “chown” Command in Linux [8 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners