> ## Content Index
> Fetch the complete content index at: https://linuxhandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# pwd command in Linux
- URL: https://linuxhandbook.com/pwd-command/
- Published: 2025-01-18T04:57:48.000Z
- Updated: 2025-01-18T04:57:48.000Z
- Description: Start your Linux command journey with the simplest of them all; pwd.
- Author: Sagar Sharma
- Tags: Commands

The `pwd` command in Linux, short for **Print Working Directory,** displays the absolute path of the current directory, helping users navigate the file system efficiently. 

It is one of the first commands you use when you [start learning Linux](https://linuxhandbook.com/courses/linux/). And if you are absolutely new, take advantage of this free course:

[Learn the Basic Linux Commands in an Hour \[With Videos\]Learn the basics of Linux commands in this crash course.![](https://linuxhandbook.com/content/images/icon/Linux-Handbook-New-Logo-27.png)Linux HandbookAbhishek Prakash![](https://linuxhandbook.com/content/images/thumbnail/Learning-Linux-beginners-1.png)](https://linuxhandbook.com/linux-command-basics/)

## pwd command syntax

Like other Linux commands, pwd also follows this syntax.

```
pwd [OPTIONS]
```

Here, you have `[OPTIONS]`, which are used to modify the default behavior of the pwd command. If you don't use any options with the pwd command, it will show the physical path of the current working directory by default.

Unlike many other Linux commands, pwd does not come with many flags and has only two important flags:

| Option     | Description                                                                |
| ---------- | -------------------------------------------------------------------------- |
| \-L        | Displays the logical current working directory, including symbolic links.  |
| \-P        | Displays the physical current working directory, resolving symbolic links. |
| \--help    | Displays help information about the pwd command.                           |
| \--version | Outputs version information of the pwd command.                            |

Now, let's take a look at the practical examples of the pwd command. 

## 1\. Display the current location

This is what the pwd command is famous for, giving you the name of the directory where you are located or from where you are running the command.

```
pwd
```

![Display the current working directory](https://linuxhandbook.com/content/images/2024/12/Display-the-current-working-directory.png)

## 2\. Display the logical path including symbolic links 

If you want to display logical paths and [symbolic links](https://linuxhandbook.com/symbolic-link-linux/), all you have to do is execute the `pwd` command with the `-L` flag as shown here:

```
pwd -L
```

To showcase its usage, I will need to go through multiple steps so stay with me. First, go to the `tmp` directory using [the cd command](https://linuxhandbook.com/cd-command-examples/) as shown here:

```
cd /tmp
```

Now, let's create a symbolic link which is pointing to the `/var/log` directory:

```
ln -s /var/log log_link
```

Finally, change your directory to `log_link` and use the pwd command with the `-L` flag:

```
pwd -L
```

![Display the logical path including symbolic links](https://linuxhandbook.com/content/images/2024/12/Display-the-logical-path-including-symbolic-links.png)

In the above steps, I went to the `/tmp` directory and then [created a symbolic link](https://linuxhandbook.com/symbolic-link-linux/) which points to a specific location (`/var/log`) and then I used the pwd command and it successfully showed me the symbolic link. 

## 3\. Display physical path resolving symbolic links 

The pwd command is one of the ways to [resolve symbolic links](https://linuxhandbook.com/follow-symbolic-link/). Meaning, you'll see the destination directory where soft link points to.

Use the `-P` flag:

```
pwd -P
```

I am going to use the symbolic link which I had created in the 2nd example. Here's what I did:

- Navigate to `/tmp`.
- Create a symbolic link (`log_link`) pointing to `/var/log`.
- Change into the symbolic link (`cd log_link`)

Once you perform all the steps, you can check the real path of the symbolic link:

```
pwd -P
```

![Follow symbolic link using the pwd command](https://linuxhandbook.com/content/images/2024/12/Follow-symbolic-link-using-the-pwd-command.png)

## 4\. Use pwd command in shell scripts

To get the current location in a [bash shell script](https://linuxhandbook.com/bash/), you can store the value of the pwd command in a variable and later on print it as shown here:

```
current_dir=$(pwd)
echo "You are in $current_dir"
```

Now, if you [execute this shell script](https://linuxhandbook.com/run-shell-script/) in your home directory like I did, you will get similar output to mine:

![Use the pwd command in the shell script](https://linuxhandbook.com/content/images/2024/12/Use-the-pwd-command-in-the-shell-script.png)

## Bonus: Know the previous working directory

This is not exactly the use of the pwd command but it is somewhat related and interesting. There is an environment variable in Linux called `OLDPWD` which stores the previous working directory path. 

This means you can get the previous working directory by [printing the value of this environment variable](https://linuxhandbook.com/print-environment-variables/):

```
echo "$OLDPWD"
```

![know the previous working directory](https://linuxhandbook.com/content/images/2024/12/know-the-previous-working-directory.png)

## Conclusion

This was a quick tutorial on how you can use the pwd command in Linux where I went through syntax, options, and some practical examples of it.

I hope you will find them helpful. If you have any queries or suggestions, leave us a comment.