pwd is a command in Linux which displays the current working directory of a user. So you might think what is the current working directory? while working in a Linux terminal you navigate among different directories in your system. Directories in Linux are organized in a tree structure under the
/ so if you use
pwd command it displays the full path where you are currently in the directory tree.
The pwd command
Pwd stands for the print working directory when you use this command in your terminal it prints the working directory of a user. It is a built-in Linux command that stores the working path in the $PWD environment variable.
Syntax of the command-
How to display the current working directory in Linux
While moving from one directory to another you can check where are you at any point of time using the pwd command. You can use the pwd command in one of the given forms –
We generally use pwd command without any argument as it is given below –
Or using option
-L will print the working directory even if contains symbolic links
Using pwd with option
-P will print the actual path without symlinks –
How to store the output of pwd command in a variable
Now let’s say you want to store the output of the pwd command in a variable called
val then use the following command in your terminal –
You can print the value inside
val variable by using –
echo "The current working directory is: $val"
How to display the previous working directory
If you want to see the previous working directory then you can use the following command in your terminal –
You can see the manual page of pwd by using the following command in your terminal –
Now you know how to check the current or previous working directory in your terminal. You can share your thought or ask queries in the comments below.