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.
Certainly, here are more examples of using the
pwd command in different scenarios:
- Basic Usage:
If you’re in the
- Navigating to a Subdirectory:
Suppose you’re in the
/home/userdirectory and you navigate to a subdirectory named “projects”:
cd projects pwd
- Using Full Path:
You can use the
pwdcommand along with other commands that require full paths. For example, creating a file in the current directory:
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:
Output might show the path of the symbolic link, not the linked location.
If you use the
pwdcommand 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)
- Using with Variables:
You can assign the result of
pwdto a variable in a shell script:
current_dir=$(pwd) echo "Current directory: $current_dir"
Current directory: /home/user
- Using Tilde (~) Shortcut:
pwdwith the tilde symbol (
~), it represents the home directory:
cd ~ pwd
Output (assuming your home directory is
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.