In this post, NewsPivot introduces what the pwd command is in Linux and how to use it to display the full path of the directory you are currently using in the terminal.

What Is pwd in Linux?

The full name of the pwd is print working directory. As one of the fundamental Linux commands, the Linux pwd command is used to display the full path of the currently selected directory in the terminal.

For example, when you are using the terminal, you may use the Linux cd command to navigate to a directory for further operation. To check if you are on the right path within the filesystem, you can run pwd in the terminal.

In short, the pwd command can display the directory you are currently in, relative to the root directory (/). This command is particularly useful when you are working on multiple terminals at the same time to avoid wrong operations between different directories.

The Syntax of pwd Command in Linux

The syntax of the Linux pwd command is:

pwd options

However, the Linux pwd command doesn’t work with any arguments or options. For special behavior, you can use it with flags.

Flags in the Linux pwd Command

The Linux pwd command is straightforward. However, you can run this command with some flags to alter its behavior slightly.

Here are some frequently used flags:

Flag 1: -L or –logical

This flag is used to print the logical current working directory. It can reflect the directory as it is shown, including any symbolic links.

pwd -L

This is the default behavior, so using pwd without any flags is equivalent to using pwd -L.

Flag 2: -P or –physical:

This flag is used to print the physical directory, which means it resolves symbolic links and shows the actual path.

pwd -P

This can be particularly helpful when you want to know the exact physical location without considering any symbolic links that may point to another directory.

How to Use the pwd Command in Linux?

Using the pwd command in Linux is simple. Both beginners and advanced users can quickly master the skills and its meaning. Here is a step-by-step guide on how to use the pwd command in Linux:

Basic Usage of the pwd Command

For example, after you run some Linux commands in the terminal, you may forget which directory you are operating now. Then, you can just type pwd in the terminal and press Enter to see the full path.

run the pwd command to see which directory is currently using

Use the pwd Command with the -L flag:

The -L flag stands for logical. When you run pwd -L, it displays the current working directory as you navigate it, including any symbolic links present in the path.

This is the default behavior just like running the pwd command, and prints the logical path, including any symbolic links.

For example, if you run a wrong command and then you don’t know where you are now, you can run the pwd -L command to view the current directory.

run the pwd -L command to view the current directory

Using pwd with the -P flag:

The pwd -P command is used to print the actual path. The -P flag stands for physical. When you run pwd -P in the terminal, it resolves all symbolic links in the path and displays the actual physical directory you are in. This command is especially useful when you want to avoid confusion caused by symbolic links.

Bottom Line

The pwd command in Linux is a simple yet essential tool for identifying your current working directory. By using this command with the -L and -P flags, you can view either the logical or physical path to solve your confusion.

Understanding how to use this command and its flags (-L and -P) can correct the navigation in the terminal, especially when working with symbolic links.

  • linkedin
  • reddit