PWD is a Linux command which Prints the Current Working directory. Sometimes it is referenced as the Present Working Directory in some books. Simply, the working directory is the directory in which you are currently working.
Every time you open a new terminal window, it opens in your home directory by default. When you navigate to a different directory using the
cd command, you change your working directory.
- -L – logical use PWD from an environment, even if it contains symlinks
- -P – physical avoid all symlinks
- –help – display this help and exit
- –version – output version information and exit
All the options are optional.
Using PWD Command (Examples)
To use the
pwd command, open a terminal window and type
pwd followed by pressing the
Enter key. The
pwd command will then print the current working directory in the terminal.
In this example, /home/atech/ is the current working directory.
NOTE: Your shell may have its own version of PWD, which usually supersedes the version described here. Please refer to your shell’s documentation for details about the options it supports. The shell built-in supports -L and –P options while /bin/pwd supports all the above four options.
Below are additional examples of the PWD command covering all options. You will learn how to print logical/physical path, getting help and finding the current version of the command.
1. Print Logical and Physical path in Linux using PWD Command
Create a symbolic link to a directory to demonstrate the working of the command as shown below.
Physical Directory: /home/atech/physical_dir
ls -l *cal_dir*
lrwxrwxrwx. 1 atech admin 12 Oct 24 09:15 logical_dir -> physical_dir physical_dir: total 0
Now, go to the logical directory and run pwd on the terminal.
It prints the logical directory path. Linux maintains a logical path value in the $PWD variable.
Now, you can direct pwd command to print the logical path using the – L and the physical path using – P option.
2. Getting the help
Now, let’s see if help option is supported by pwd command or not.
-bash: pwd: --: invalid option pwd: usage: pwd [-LP]
You can clearly see, pwd shell built-in does not support –help option.
What about /bin/pwd?
Yes, it supports. See the below example.
3. Finding the version
You can use the –version option to print the version of the pwd command.
Directory paths are long in Linux, Unix, and Unix-alike systems. The command prompt doesn’t show the entire path by default. When you are lost and want to know where (in which directory) you are, just type PWD on the command prompt to print the entire path.
I hope you found this article useful. Please share and subscribe.
Refer to this man page for additional details.