Note: Before delving into this Answer, an overview of Linux may be helpful.
Knowing our current location within a file system is crucial for managing files inside Linux. One of the most basic command for this purpose is pwd
, which stands for “print working directory.” In this Answer, we’ll explore how to use the pwd
command to display the path of the current working directory on a Linux system.
When we open a terminal in a Linux system, we start in a specific directory known as the user’s home directory. As we navigate through the file system using commands like cd
(change directory), our current working directory changes accordingly. Enter ls
in the terminal above to see the content of the current directory.
For this example, cd
into any directory. An example of one such command is:
cd usercode
Now, we’ll use the pwd
command:
pwd
This will output the full path of the directory we’re currently in, i.e., /usercode
.
Let’s explore some flags we can append to this command.
-logical
flagWe can use -L
or –logical
as a flag:
pwd -L
This option above displays the logical current working directory. It does not resolve symbolic links, showing the path exactly as we navigate to it. For example, if we are in usercode
directory, the above command will display /usercode
as the output.
-physical
flagWe can use -P
or –physical
as a flag:
pwd -P
This option displays the physical current working directory. It resolves symbolic links, showing the “real” path.
For this example, we’ve created an example directory. Navigate to it as follows:
cd ~/logical_physical_demo/main_directory/symlink_to_subdirectory
Test both of these commands in the terminal provided prior.
Use the terminal below to enter commands:
Now we have understood how to display the current working directory path in Linux, let's test our knowledge on this:
What does the pwd
command stand for in a Linux system?
Present working directory
Print working directory
Path working directory
Position working directory
Flag | Description | Example |
| Displays the physical current working directory by resolving the symbolic links. |
|
| Displays the logical current working directory, without resolving the symbolic links. |
|
Free Resources