Introduction
- Introduction
- Usage
- Syntax
- What does pwd command do?
- Option -L
- Option -P
- Where is pwd binary located?
- Exit codes
- Conclusion
One of the very first commands that one learns when starting with Linux or Unix Operating Systems is the pwd command.
pwd stands for print working directory.
It is a shell built-in general-purpose command.

Usage:
To display the current working directory name
Syntax:
pwd [-L | -P]
What does pwd command do?
When you execute the pwd command on any shell prompt, it will print to the standard output (stdout) the name of the current directory that the user is in.
The name is displayed starting from the root directory (i.e. the / (slash) at the start of the name) followed by slashes that denotes separation between directories (nested directories)
The name after the last slash is the name of your current directory you are in.
Example 1:# pwd
/Users/code2care/Desktop
In the above example Desktop is the current directory located within User -> code2care.
Example 2:# pwd
/
If you just get / as output then you are in the root directory.
Options:
There are only two options that you can use with the pwd command i.e. -L and -P
-L (--logical)When -L option is used with pwd command it will display the logical current working directory, which is the value of the PWD environment variable.
Example 3:# pwd -L
/home/mydirs
-P (--physical)
When -P option is used with the pwd command it will display the symbolic link if it is associated with the current directory, if not, it will simply print out the PWD value as with -L option.
Example 4:# cd /home/mydirs
# pwd -P
/home/dir1/dir2/dir3
As you can see in the above example, we changed the directory to /home/mydirs which is actually a symbolic link to /home/dir1/dir2/dir3 hence -P options prints out /home/dir1/dir2/dir3 instead of /home/mydirs.
Note: The -L option will not work if the PWD environment variable is exported by the shell.
Where is pwd binary located?
The pwd file/binary is located in /bin/pwd
Error codes associated with PWD command
0 -> success
> 0 -> an error occurs
If you provide an incorrect option/flag, you will get an error,
# pwd -A
pwd: bad option: -A
# pwd -X
bash: pwd: -X: invalid option
pwd: usage: pwd [-LP]

Conclusion
To know where are you currently when working on a Terminal Shell, make use of pwd command. Use -P option to know the real physical location of the current directory.
Facing issues? Have Questions? Post them here! I am happy to answer!
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
- Android Shared Preferences API tutorial - Android
- What is macOS Ventura? - MacOS
- [Fix] java.net.MalformedURLException: unknown protocol - Java
- How to turn off autocomplete in input fields in HTML Form - Html
- How to know my IP on Mac Ventura 13.0 - MacOS
- Gmail Unable to upload because it is a folder or a package (like an application bundle or RTFD document) - HowTos
- Format Code in Visual Studio - VS Code [Mac/Windows/Linux] - HowTos
- Python: Pandas Merge DataFrames on Index Example - Python