Linux pwd utility

How can I see the current directory on a Linux system? How do I find the full path to the current file location? The Linux pwd utility will help us with this.

  1. Pwd utility
  2. Options linux pwd command

Pwd utility

linux pwd utility

The pwd command prints the full path to the current / working directory relative to the root directory. If you run it without keys, then the result of its work will be as follows:

$ pwd
/home/user

Options linux pwd command

-P, --physical – the full path will be printed, and symbolic links will be converted to the original path. This method is used by default.

-L, --logical – displays the full path, but symbolic links will not be converted to the original path.

For example, let’s create a symbolic link to the /etc directory and navigate to it:

$ ln -s /etc/ etc
$ cd etc

And let’s see how the linux pwd utility works with the -P and -L options:

[user@linux etc]$ pwd -P
/etc
[user@linux etc]$ pwd -L
/home/user/etc

As you can see from the example, in the first case, the real directory is displayed, in the second, there is no conversion.

--help – display brief help for the utility:

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

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

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

    Exit Status:
    Returns 0 unless an invalid option is given or the current directory
    cannot be read.

You can find even more useful Linux utilities on this page.