Whether you’re developing Python apps on Linux, or just organizing your files from the shell, it’s important to be able to find out which folder you are currently navigating.
The pwd command will do that for you – it prints the name of the current directory you are navigating in the terminal – including its full path.
This is extremely useful in any Linux environment as it will remove all confusion about which folder you’re in, as it’s very common for there to be multiple folders of the same name in a system.
See the below example:
linuxscrew-host:pictures screw $
The default Bash terminal prompt shows your hostname (linuxscrew-host), username (screw), and the current folder (pictures). If you have more than one folder called pictures, you might not know which one you are currently in based on the information displayed.
Syntax and Usage
Here’s the syntax for pwd:
pwd [OPTIONS]...
Here it is in use!
pwd
(Yes, you just type pwd – it’s that easy). In response you’ll get the full path of the current working directory, in this case, it’s /Users/screw/pictures.
Result:
linuxscrew-host:pictures screw$ pwd /Users/screw/pictures
Options
pwd is a simple command, there are only two options you can pass to it:
-L, --logical Display the logical current working directory -P, --physical Display the physical current working directory (all symbolic links resolved)
Options can be passed to the command in the Bash shell as follows:
pwd -L -P
- A symlink is a link or reference to another file or directory (You’ve probably seen them as shortcuts in Windows, which serve a similar function)
Conclusion
pwd is a simple, short command with a clear purpose, so this was a very short article!
To learn more about Linux commands and Bash scripting, check out our full list of Bash articles!