Pwd command is used Linux to print the path of the current working directory, starting from the root (/). In this tutorial, we learn about pwd command with useful examples.
pwd is a shell built-in command which stands for "Print Working Directory". It is a very basic command used in Linux. pwd command print the complete path current working directory from the root. It simply prints the content of the environment variable $PWD.
You may find a standalone executable version of pwd in /bin/pwd and /usr/bin/pwd, a slight variant of shell built-in. To display the list of all locations having executable name pwd:
$ type -a pwd
pwd is a shell builtin pwd is /usr/bin/pwd pwd is /bin/pwd
Pwd command has two options, -L (--logical) and -P (--physical). We will learn its difference in the next section using an example.
-L - use PWD from environment, even if it contains symlinks -P - avoid all symlinks and print the actual path
Print the path of the current working directory
Open your terminal and type
pwd to print the current working directory.
Otherwise, you can print the content of $PWD environment variable.
$ echo $PWD
To explain the pwd options -L and -P, let me create a symlink pointing to the directory.
Here I am creating a directory named documents and create a symlink named Mydocuments on my Desktop.
$ mkdir /home/bobbin/documents $ ln -s /home/bobbin/documents ~/Desktop/Mydocuments
The output of pwd and pwd -L is the same which prints the path of the symlink, whereas pwd -P print the actual physical location. The environment variable $PWD is the same as pwd -L.
In this short tutorial, we learned pwd command in Linux and learned to display the current working directory.
Please let us know if you have any questions or feedback in the comment section.