In this article we are going to take a look at the
pwd command, one of the most basic commands in Linux.
We will find out how to use the pwd command to write to standard output the full path name of your current directory and will learn the difference between the built-in pwd command and the external pwd command written by Jim Meyering.
What Does PWD Do??
pwd is an acronym for “Print Working Directory.” The pwd command is one of the most frequently used commands by Linux system administrators. It works on Linux and other UNIX like operating systems and is a built-in shell command, available on Bash shell, korn, ksh, and so on.
pwd command prints the current working directory name with the complete path starting from root (/). It is also an environmental variable.
Difference Between Shell “pwd” and “/bin/pwd”
Linux shells usually come with two types of pwd command: built-in pwd and binary version. To find out, you can use the following command:
The screenshot below shows that bash shell comes with both the built-in pwd command and binary version.
What’s a Current Working Directory?
The current working directory is the directory in which you are currently operating commands such as
cd using bash or korn shell or zsh (zshell).
Syntax of PWD Command
Every Linux command has its own syntax. Without basic knowledge of command syntax, executing commands on a Linux terminal might seem like a tedious task.
Below is a basic syntax of the pwd command:
Pwd command comes with different options which allows us to use this command in different ways. However, you can still use the pwd command without any arguments.
Let’s take a look at the most basic options of the pwd command. To find a list of pwd command options, you can type
pwd --help on the terminal.
-L: Prints the value of $PWD if it names the current working directory. In other words, it prints or displays the current working directory.
Even without the
-L, just typing the pwd on terminal does the same thing.
-P: Prints the physical directory without any symbolic links. A symbolic link is a special kind of file that creates a shortcut to a file or points to another file. Print the physical directory without any symbolic links by using the commands below:
Assuming you have used the
cd command several times and want to know your current working directory, you can use the following commands to do so:
Both commands display your current working directory.
How to Print the Version of PWD Command
To find the version of the built-in pwd command on your terminal, you can use the binary version to do so:
The pwd command is one of the most commonly used commands on Linux computers. It is quite simple to use when you know what it does.
Image credit: Russian hacker hacking the server in the dark by Lifestyle discover/Shutterstock