How to use the command pwd (with examples)
- Linux
- December 25, 2023
The pwd
command stands for “Print Working Directory”. It is used to print the name of the current working directory in the terminal. This command is useful for quickly checking the directory you are currently working in.
Use case 1: Print the current directory
Code:
pwd
Motivation: This use case is useful when you want to know the absolute path of the directory you are currently working in. It allows you to easily confirm the location of your files and navigate to the correct directories when working with different files or running commands.
Explanation: The pwd
command with no additional arguments simply prints the absolute path of the current working directory. It does not resolve any symbolic links or logical paths, just gives you the path as is.
Example output:
/Users/username/Documents
Use case 2: Print the current directory, and resolve all symlinks
Code:
pwd --physical
Motivation: Sometimes, the current working directory may contain symbolic links. When you want to see the actual physical path of the directory, without any symbolic links, this use case comes in handy.
Explanation: The --physical
argument, when used with the pwd
command, resolves any symbolic links in the current working directory and prints the physical path, i.e., the path without any symbolic links.
Example output:
/Users/username/Projects/my-app
Use case 3: Print the current logical directory
Code:
pwd --logical
Motivation: This use case is useful when you want to see the logical path of the current working directory. The logical path may be different from the physical path, especially when working with symbolic links.
Explanation: The --logical
argument, when used with the pwd
command, prints the logical path of the current working directory. It takes into account symbolic links and provides the path that is logical within the file system.
Example output:
/Users/username/Projects/my-app
Conclusion:
The pwd
command is a simple yet powerful tool for printing the current working directory. By default, it provides the absolute path, but you can also use additional arguments to print the physical or logical path. This command is essential for navigating the file system and working with files and directories in the terminal.