Linux Command: pwd

Published on November 29, 2021 at 6:59 am by LEW

Introduction

The pwd (short for print working directory) command is a standard utility command in Linux Distributions. It displays the path to the current working directory. The pwd command only has two few options, making it one of the easier commands to learn.

Syntax and Function

The syntax of the pwd command is:

pwd [options]

Examples

To use pwd, you simply type it at any time by itself, and it will return the directory you are working in.

pwd

You may notice that sometimes your directory path is listed in your bash prompt. You may also have notices that when you are in your home directory, you see a “~” displayed. So you may be wondering why you need this command.

In some cases, the directory path may have been removed form the bash prompt (something else I need to write a how to post about) because you find yourself multiple directories deep, and displaying the path can look a little confusing. In this case pwd is very useful.

Another use case is when you are in a linked directory, and need the correct actual path or the correct linked path.

A final use case is using pwd in a bash script where you need to determine the working directory.

Note that pwd is a built in console command and there is a pwd binary in the /bin directory. These behave slightly differently. Normally you will be using the built in command. The difference comes when using pwd without any options. The built in will display the path, while the binary version will display the linked path if it exists

Options

As mentioned, pwd only has a couple of options.

Conclusion

The pwd command is simple and useful when you need it. it is an easy command to learn and add to your console toolbox.

Add New Comment

Your email address will not be published. Required fields are marked *