The pwd command in Linux stands for “print working directory.” It is used to display the current directory you are in within the file system hierarchy. This command can be particularly helpful when navigating the command line interface and working with different directories.
Usage:
pwd
Example:
Certainly, here are more examples of using the pwd command in different scenarios:
- Basic Usage:
If you’re in the/home/userdirectory:
pwd
Output:
/home/user
- Navigating to a Subdirectory:
Suppose you’re in the/home/userdirectory and you navigate to a subdirectory named “projects”:
cd projects
pwd
Output:
/home/user/projects
- Using Full Path:
You can use thepwdcommand along with other commands that require full paths. For example, creating a file in the current directory:
touch $(pwd)/newfile.txt
This will create a file named “newfile.txt” in the current directory.
- Symbolic Links:
If you’re in a symbolic link directory that points to another location:
pwd
Output might show the path of the symbolic link, not the linked location.
- Subshell:
If you use thepwdcommand within a subshell (enclosed in parentheses), it will give you the path of the current directory without affecting your current location in the main shell:
(cd /tmp; pwd)
Output:
/tmp
- Using with Variables:
You can assign the result ofpwdto a variable in a shell script:
current_dir=$(pwd)
echo "Current directory: $current_dir"
Output:
Current directory: /home/user
- Using Tilde (~) Shortcut:
When usingpwdwith the tilde symbol (~), it represents the home directory:
cd ~
pwd
Output (assuming your home directory is /home/user):
/home/user
The pwd command is a simple yet essential tool that helps you keep track of your location within the file system, enabling efficient navigation and manipulation of directories and files.


