- What does pwd command do?
- Option -L
- Option -P
- Where is pwd binary located?
- Exit codes
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.
Have Questions? Post them here!
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- Google Webmaster : An error has occurred. Please try again later - Google
- How to Screenshot on Mac Ventura 13 - Step by Step Guide - MacOS
- Gmail Unable to upload because it is a folder or a package (like an application bundle or RTFD document) - HowTos
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs - Python-Programs
- Calculate days between dates using dateutils ddiff command - Linux
- ls command sort by file size [Linix/UNIX/macOS/bash] - Linux
- [Fix] Spring Tool Suite STS Code Autocomplete not working with Eclipse - Eclipse
- How to uninstall GarageBand from Mac - MacOS