PWD is a Linux command which Prints the Current Working directory. Sometimes it is referenced as the Present Working Directory in some books.
Below is the syntax of pwd command,
Below are the options:
- -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
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 above four options.
Refer to this man page for additional details.
How to use the PWD command (Examples)
We will cover all options supported by this command. Simply open the terminal and run the command to display the current working directory as shown below.
$ pwd /home/atech/
1. Print Logical and Physical path
Here we will see the working of -L and -p options.
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 use the cd command to go to the logical directory and run pwd on the terminal.
$ cd logical_dir $ pwd /home/atech/logical_dir
You can see it prints the logical directory path.
$PWD also holds the logical path.
$ echo $PWD /home/atech/logical_dir
-L options print the logical path while -P print the actual physical path.
$ pwd -L /home/atech/logical_dir $ pwd -P /home/atech/physical_dir
2. Getting help
Now, let’s see help option is supported by this command or not.
$ pwd – help -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.
/bin/pwd – help Usage: /bin/pwd [OPTION]... Print the full filename of the current working directory. -L, – logical use PWD from environment, even if it contains symlinks -P, – physical avoid all symlinks --help display this help and exit --version output version information and exit 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. Report pwd bugs to [email protected] GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'pwd invocation'
3. Finding the version
You can use the –version option to print the version of the command.
$ /bin/pwd – version pwd (GNU coreutils) 8.4 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Jim Meyering.
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.