The PWD (a.k.a. “present working directory”) will print the path of the directory you are currently working in, starting from the root directory to the current directory.
|Description||PWD (Present Working Directory)|
|Root or Sudo Privileges||No|
|Host System and Architecture||Ubuntu 22.10 (x64)|
|OS Compatibility||Ubuntu, Manjaro, Fedora, etc.|
Syntax of the PWD Command
The PWD command requires only one flag, and that is optional.
$ pwd [OPTION]
The PWD command recognizes the following two options:
|-L||Display the value assigned to the $PWD variable.|
|-P||Display the physical directory without any symbolic links.|
By default, PWD without any flag takes the “
-L” flag in action to display the current working directory.
Printing the Current Directory Path
The following command will print the absolute path of the directory you are working in, from the root directory to the current working directory.
$ pwd # OR $ pwd -L
If you are working inside the symbolic directory, then the PWD command will print the symbolic link where you are currently working.
~/Documents/sampledir$ pwd #OR ~/Documents/sampledir$ pwd -L
Printing the Actual Directory Path (Ignoring Symbolic Links)
If you want to print the actual symbolic link path where it is pointing, use the “
~/Documents/sampledir$ pwd -P
~/Documents/sampledir” is the symbolic link to the “
Finding the PWD Path
Execute the following command to print all the locations having the executable name “
pwd” using the type command.
$ type -a pwd
Taking the /bin/pwd in Action
You can use the PWD command to print the current working directory, or the “
/bin/pwd” command. However, both are a little bit different from each other.
For example, by default, the PWD command uses the “
-L” flag to print the current working directory, but in the case of the “
/bin/pwd” command, it uses the “
-P” flag by default to print the path of the directory that the symbolic link points towards.
~/Documents/sampledir$ pwd #AND ~/Documents/sampledir$ /bin/pwd
And you can specify the “
-P” flag separately for the PWD command; the “
/bin/pwd” command requires the “
-L” flag to print the current working directory.
~/Documents/sampledir$ pwd -P #OR ~/Documents/sampledir$ /bin/pwd -L
Echo $PWD Variable
The PWD command uses the $PWD environment variable to store the path of the current working directory, working like the “
~/Documents/sampledir$ echo $PWD
Printing the $PWD and $OLDPWD Variables
It will print the current and previous working directories as shown.
~/Documents/sampledir$ echo $PWD $OLDPWD
That’s all about the PWD command. If you have a query related to this topic, feel free to discuss it in the comment section.