TrumanWong

pwd

Displays the absolute path of the current working directory.

Supplementary instructions

The pwd (English full spelling: print working directory) command is used to display the user's current working directory (displayed as an absolute path).

Built-in commands

Summary

pwd [-LP]

Options

-L (default) Print the value of the environment variable "$PWD", which may be a symbolic link.
-P Prints the physical location of the current working directory.

return value

The return status is success unless an illegal option is given or the current directory cannot be read.

Notice

  1. This command is a built-in bash command. For related help information, please see the help command.

External commands

Summary

pwd [OPTION]...

The main purpose

  • Display the current working directory.

Options

-L, --logical Print the value of the environment variable "$PWD", which may be a symbolic link.
-P, --physical (default) Print the physical location of the current working directory.
--help Display help information and exit.
--version Display version information and exit.

return value

The return status is success unless an illegal option is given or the current directory cannot be read.

Notice

  1. This command is a command in the GNU coreutils package. For related help information, please view man pwd or info coreutils 'pwd invocation'.
  2. To enable or disable built-in commands, please see the enable command. For issues with the priority of the same name, please see the relevant discussion in the examples section of the builtin command.
  3. When the built-in is not disabled and the pwd function is not defined in the current environment, use /usr/bin/pwd to point to the pwd of coreutils and use pwd to point to the bash built-in pwd .

example

View current path

[root@localhost var]#pwd
/var

Display the file path that the soft link file ultimately points to

[root@localhost ~]# cd /var/ # Enter the /var directory. There is a mail soft link file in this directory.
[root@localhost var]# ls -al
total 164
...
lrwxrwxrwx 1 root root 10 Oct 17 2015 mail -> spool/mail

[root@localhost var]# cd mail/ # Enter the mail directory, where mail is the connection file.
[root@localhost mail]# pwd # By default, the connection file is used and the full path of the connection file is directly displayed.
/var/mail

Using the -P parameter, what is displayed is not the logical path, but the file that the connection (soft link) file ultimately points to.

[root@localhost mail]# pwd -P
/var/spool/mail