For those working with Linux command Line, pwd (which stands for Print Working Directory) is an important command. pwd tells where you are – in which directory, starting from the root (/). Specially for Linux beginners, who may get lost amidst of directories in command Line Interface while navigation, command pwd comes to rescue. This command is built in shell command and is available on most of the shell (bash, Bourne shell, ksh,zsh), etc.

This article presents some useful examples of using pwd command, all tested on Ubuntu 18.04 LTS.

Basic syntax

pwd [OPTION]...

man page explanation:

Print the full filename of the current working directory.

 

How it works

It is very easy to use pwd command. Just run the pwd command without any options, and you’ll get the full path to the current working directory in output:

pwd

Example:

mxforge@ansh:~$ pwd
/home/mxforge

Most shells, including bash, have pwd built-in. Just run the following command:

type -a pwd

The following output will be returned:

pwd is a shell builtin
pwd is /bin/pwd

 

The difference between pwd and /bin/pwd

pwd is a built into the shell, while /bin/pwd is the tool that comes with your Linux distribution.

As man page explains:

NOTE: Your shell may have its own version of pwd, which usually supersedes the version described
here. Please refer to your shell's documentation for details about the options it supports.

 

Making pwd use PWD from the environment

You can use the -L command line option to make pwd use PWD from the environment.

Create a symlink to the current directory (/home/mxforge in our case):

ln -s . dir_symlink

and enter it:

cd dir_symlink

Execute the following command:

/bin/pwd

We have got the following output:

/home/mxforge

Next, run the following command:

/bin/pwd -L

And we have got the following output:

/home/mxforge/dir_symlink

 

Avoid all symbolic links

You can use the -P command line option to make pwd avoid all symbolic links. For instance:

/bin/pwd -L

will return the output:

/home/mxforge/dir_symlink

But with -P

/bin/pwd -L -P

the output will be:

/home/mxforge

If no option is specified, -P is assumed by default.

 

pwd is one of the simplest yet most popular and most widely used command, a basic to use Linux terminal.