pwd (with examples)
The pwd
command stands for “print working directory” and is used to display the current directory you are working in. It can be particularly useful when navigating through the directory structure or when scripting.
Print the current directory
To print the current directory, simply enter the pwd
command:
pwd
Motivation: This use case is helpful when you want to quickly verify your current working directory without having to navigate through the file system.
Arguments: There are no arguments needed for this use case.
Example output:
/home/user/Documents
This output indicates that the current working directory is /home/user/Documents
.
Print the current directory and resolve all symlinks
To print the current directory and resolve all symbolic links (i.e., show the “physical” path), use the -P
option with the pwd
command:
pwd -P
Motivation: By resolving all symbolic links, you are able to see the actual physical path of the current directory. This can be useful when dealing with symbolic links or when you want to obtain the absolute path of the directory.
Arguments:
-P
: This option tells thepwd
command to resolve all symbolic links in the path and display the physical path.
Example output:
/home/user/PhysicalDocuments
This output indicates that the current working directory, after resolving all symbolic links, is /home/user/PhysicalDocuments
.
In conclusion, the pwd
command is a handy tool for quickly identifying the current working directory. Whether you need to verify your current location or obtain the physical path of the directory, pwd
has got you covered. By understanding the different use cases and arguments available, you can make the most out of this command in your everyday Linux adventures.