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.
To display the current working directory name
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.
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
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]
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!
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- [Event Log] Android Studio performance could be improved - Android-Studio
- [Android Studio] Error: Missing system image on device - Android-Studio
- Fix Power Automate FLOW error - InvalidTemplate Unable to process template language expressions in action - Microsoft
- Python: Convert Set to a List - Python
- Top 10 emerging breakthrough trending technologies - HowTos
- Is Facebook is down? Is it just for me? - Facebook
- Set width and height for the label in tkinter - Python
- Android Studio : Build Tools 23.0.0 rc1 is deprecated - Android-Studio