Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To print current/present working directory environment variable $PWD and command pwd are available. So, What is difference in usage of both? or What should be chose for specific purpose?

share|improve this question
up vote 5 down vote accepted

That depends on what you're doing. First of all, $PWD is an environment variable and pwd is a shell builtin or an actual binary:

$ type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

Now, the bash builtin will simply print the current value of $PWD unless you use the -P flag. As explained in help pwd:

pwd: pwd [-LP]
Print the name of the current working directory.

  -L    print the value of $PWD if it names the current working
  -P    print the physical directory, without any symbolic links

By default, `pwd' behaves as if `-L' were specified.

The pwd binary, on the other hand, gets the current directory through the getcwd(3) system call which returns the same value as readlink -f /proc/self/cwd. To illustrate, try moving into a directory that is a link to another one:

$ ls -l
total 4
drwxr-xr-x 2 terdon terdon 4096 Jun  4 11:22 foo
lrwxrwxrwx 1 terdon terdon    4 Jun  4 11:22 linktofoo -> foo/
$ cd linktofoo
$ echo $PWD
$ pwd
$ /bin/pwd

So, in conclusion, on GNU systems (such as Ubuntu), pwd and echo $PWD are equivalent unless you use the -P option but /bin/pwd is different and behaves like pwd -P.

share|improve this answer
One difference is that using $PWD when available will avoid forking a subcomand like echo or pwd. This makes it advantageous for performance and program tracing. – Joe Atzberger Jun 4 '14 at 18:55

Both will return the same result if you use them without options for all working directories, including when in symbolic links.

However, from man pwd:

-P, --physical
    avoid all symlinks

This would mean executing pwd -P when in symbolic links which point to some other directories will print the path to the original directory.

As an example, if you have a symbolic link /var/run that points to /run and you are currently in /var/run/ directory, executing

echo $PWD

will return:


and will be the same for pwd. However, if you execute:

pwd -P

will return


Thus, it depends which path you require: the actual path without symbolic links or the present directory ignoring the symbolic links. The only difference between between pwd -P and echo $PWD is when there are symbolic links.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.