PWD Command in Linux – (How to) Print Working Directory

PWD command in Linux

PWD is a Linux command which Prints the Current Working directory. Sometimes it is referenced as the Present Working Directory in some books.

Syntax

pwd [options]…

Options

  • -L – logical use PWD from an environment, even if it contains symlinks
  • -P – physical avoid all symlinks
  • –help – display this help and exit
  • –version  – output version information and exit

All the options are optional.

Open the terminal and run the pwd command to display the current working directory.

$ pwd
/home/atech/

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. The shell built-in supports -L and –P options while /bin/pwd supports all the above four options.

PWD Command( Examples)

Below are examples of the PWD command covering all options.

1. Print Logical and Physical path in Linux using PWD Command

Create a symbolic link to a directory to demonstrate the working of the command as shown below.

Physical Directory: /home/atech/physical_dir
Logical Directory:/Home/atech/logical_dir

$ls -l *cal_dir*
lrwxrwxrwx. 1 atech admin 12 Oct 24 09:15 logical_dir -> physical_dir

physical_dir:
total 0

Now, go to the logical directory and run pwd on the terminal.

$ cd logical_dir
$ pwd
/home/atech/logical_dir

It prints the logical directory path. Linux maintains a logical path value in the $PWD variable.

$ echo $PWD
/home/atech/logical_dir

Now, you can direct pwd command to print the logical path using the – L and the physical path using – P option.

-L options

$ pwd -L
 /home/atech/logical_dir

-P options

$ pwd -P
/home/atech/physical_dir

2. Getting the help

Now, let’s see help option is supported by pwd command or not.

$ pwd --help
-bash: pwd: --: invalid option
pwd: usage: pwd [-LP]

You can clearly see, pwd shell built-in does not support –help option.

What about /bin/pwd?

Yes, it supports. See the below example.

/bin/pwd --help
Usage: /bin/pwd [OPTION]...
Print the full filename of the current working directory.

-L, --logical use PWD from environment, even if it contains symlinks
-P, --physical avoid all symlinks
--help display this help and exit
--version output version information and exit

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.

Report pwd bugs to [email protected]
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'pwd invocation'

3. Finding the version

You can use the –version option to print the version of the pwd command.

$ /bin/pwd --version
pwd (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jim Meyering.

Summary

Directory paths are long in Linux, Unix, and Unix-alike systems. The command prompt doesn’t show the entire path by default. When you are lost and want to know where (in which directory) you are, just type PWD on the command prompt to print the entire path.

I hope you found this article useful. Please share and subscribe.

Refer to this man page for additional details.

pwd man page

Share This:
Scroll to Top