Command Line · Lesson 2 of 19
pwd (Print Working Directory)
0 / 4 checkpoints answered
Practice
In the practice terminal below, run: pwd It prints the full path of the directory you are currently in.
Three letters, then Enter.
In Linux, files and directories are organized in a hierarchy called the filesystem. Before you can move around confidently, you need to know where you are. The pwd command answers that question by printing your current working directory.
The Directory Tree in Linux
The entire filesystem starts from a single top-level directory called the root directory, represented by a forward slash (/). From the root, the directory tree branches into subdirectories, which can contain files and more subdirectories.
Here is a simplified example of what this structure looks like:
/
|-- bin
| |-- file1
| |-- file2
|-- etc
| |-- file3
| `-- directory1
| |-- file4
| `-- file5
|-- home
|-- var
CheckIn the directory tree above, how are home and etc related to /?
press 1/2/3 to answer · → next lesson
Understanding File Paths
The location of any file or directory is described by its path. A path is a sequence of directories that leads from a starting point to a specific destination.
For example, if you have a folder named pete inside /home, and a Movies folder inside pete, the full path is:
/home/pete/Movies
A path that starts with / is an absolute path because it starts at the root directory. A path such as Movies is relative because it depends on your current location.
CheckWhat makes /home/pete/Movies an absolute path?
press 1/2/3 to answer · → next lesson
What is the Full Form of PWD in Linux?
The full form of pwd is "print working directory." Your working directory is the directory where your shell is currently located. Commands that use relative paths start from this location.
CheckWhat does pwd stand for?
press 1/2/3 to answer · → next lesson
Using the pwd Command
To find your current directory, type pwd and press Enter.
$ pwd
/home/pete
The output is an absolute path. In this example, the shell is currently in the pete user's home directory.
The exact output may be different on your system because your username, home directory, and current location may differ. The pwd command only prints information; it does not change your working directory. By contrast, cd changes the directory where your shell is located.
CheckWhich action checks your current directory without changing it?
press 1/2/3 to answer · → next lesson
Why pwd is Useful
Use pwd when:
- You are following instructions and need to confirm your location.
- A command failed because a file path was wrong.
- You moved through several directories and lost track of where you are.
- You want to copy the current directory path into another command.
For example:
$ pwd
/home/pete/projects
$ ls
app.py README.md
This tells you that app.py and README.md are located in /home/pete/projects.
To reinforce your understanding of Linux filesystem navigation and identifying your current location, try these hands-on labs:
- Linux pwd Command: Directory Displaying - This lab provides a focused overview and practical usage of the
pwdcommand, directly aligning with the lesson's introduction to finding your current directory. - Linux Directory Navigation - Put your basic Linux command-line skills to the test by navigating through various directories, solidifying your understanding of paths and the file system structure.
- Linux cd Command: Directory Changing - Learn to efficiently navigate your file system using the
cdcommand, understanding different techniques for changing directories and exploring the file structure.
Summary
You can now use pwd to identify your current location in the Linux filesystem.
- Recognize the root of the directory tree.
- Distinguish an absolute path from a relative path.
- Explain what
pwdmeans and what it reports. - Check your working directory without changing it.
Lesson complete
You finished pwd (Print Working Directory). Nice work — keep the momentum going.