pwd (Print Working Directory)
100%

Command Line · Lesson 2

pwd (Print Working Directory)

Learn how to use pwd to identify your current location in the Linux filesystem.

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

In the directory tree above, how are home and etc related to /?

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.

What makes /home/pete/Movies an absolute path?

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.

What does pwd stand for?

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.

Which action checks your current directory without changing it?

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:

  1. Linux pwd Command: Directory Displaying - This lab provides a focused overview and practical usage of the pwd command, directly aligning with the lesson's introduction to finding your current directory.
  2. 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.
  3. Linux cd Command: Directory Changing - Learn to efficiently navigate your file system using the cd command, understanding different techniques for changing directories and exploring the file structure.

Lesson complete

You finished pwd (Print Working Directory)

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 pwd means and what it reports.

  • Check your working directory without changing it.

Keep your learning progress

Create a free account to save this lesson and continue learning on any device.

Create a free account
Next Lesson
Back to Command Line