The Beginner’s Guide to the pwd Command in Linux

In this article we are going to take a look at the pwd command, one of the most basic commands in Linux.

We will find out how to use the pwd command to write to standard output the full path name of your current directory and will learn the difference between the built-in pwd command and the external pwd command written by Jim Meyering.

pwd is an acronym for “Print Working Directory.” The pwd command is  one of the most frequently used commands by Linux system administrators. It works on Linux and other UNIX like operating systems and is a built-in shell command, available on Bash shell, korn, ksh, and so on.

The pwd command prints the current working directory name with the complete path starting from root (/). It is also an environmental variable.

Linux shells usually come with two types of pwd command: built-in pwd and binary version. To find out, you can use the following command:

The screenshot below shows that bash shell comes with both the built-in pwd command and binary version.

types-of-pwd

The current working directory is the directory in which you are currently operating commands such as ls, cat, or cd using bash or korn shell or zsh (zshell).

Every Linux command has its own syntax. Without basic knowledge of command syntax, executing  commands on a Linux terminal might seem like a tedious task.

Below is a basic syntax of the pwd command:

Pwd command comes with different options which allows us to use this command in different ways. However, you can still use the pwd command without any arguments.

Let’s take a look at the most basic options of the pwd command. To find a list of pwd command options, you can type pwd --help on the terminal.

list-pwd-options

  • -L: Prints the value of $PWD if it names the current working directory. In other words, it prints or displays the current working directory.

current-working-directory

Even without the -L, just typing the pwd on terminal does the same thing.

current-directory

  • -P: Prints the physical directory without any symbolic links.  A symbolic link is a special kind of file that creates a shortcut to a file or points to another file. Print the physical directory without any symbolic links by using the commands below:

physical-directory

Assuming you have used the cd command several times and want to know your current working directory, you can use the following commands to do so:

print-current-directory

print-working-directory

Both commands display your current working directory.

To find the version of the built-in pwd command on your terminal, you can use the binary version to do so:

pwd-version

The pwd command is one of the most commonly used commands on Linux computers. It is quite simple to use when you know what it does.

Image credit: Russian hacker hacking the server in the dark by Lifestyle discover/Shutterstock

Leave a Reply

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.