In Linux, use the PWD command to view the full path to the current working directory. Simply put, you will have a current working directory every time you operate in a terminal.
When unsure of the current location, PWD is used to determine the exact location of the current directory within the file system.
1. Command format:
PWD [Options]
2. Command function:
View the full path to the current working directory
3. Common parameters:
Normally without any parameters
If the directory is a link:
Format: Pwd-p shows the actual path, not the link path.
4. Common examples:
Example 1: Viewing the full path of the default working directory with the PWD command
Command:
Pwd
Output:
[root@localhost ~]# pwd
/Root
[root@localhost ~]#
Example 2: Use the PWD command to view the specified folder
Command:
Pwd
Output:
[root@localhost ~]# cd/opt/soft/
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]#
Example three: When a directory connection is linked, Pwd-p displays the actual path, not the connection path; pwd shows the connection path
Command:
Pwd-p
Output:
[root@localhost soft]# cd/etc/init.d
[root@localhost init. D]# pwd
/etc/init. D
[root@localhost init. D]# pwd-p
/etc/RC. D/init. D
[root@localhost init. D]#
Example 4:/bin/pwd
Command:
/bin/pwd [Options]
Options:
-L directory connection link, output connection path
-P Output Physical path
Output:
[root@localhost init. D]#/bin/pwd
/etc/RC. D/init. D
[root@localhost init. D]#/bin/pwd--help
[root@localhost init. D]#/bin/pwd-p
/etc/RC. D/init. D
[root@localhost init. D]#/bin/pwd-l
/etc/init. D
[root@localhost init. D]#
Instance five: The current directory is deleted, and the PWD command still displays that directory
Output:
[root@localhost init. D]# cd/opt/soft
[root@localhost soft]# mkdir removed
[root@localhost soft]# cd removed/
[root@localhost removed]# pwd
/opt/soft/removed
[root@localhost removed]# rm.. /REMOVED-RF
[root@localhost removed]# pwd
/opt/soft/removed
[root@localhost removed]#/bin/pwd
/bin/pwd: couldn 't Find directory entry in "..." With matching i-node
[root@localhost removed]# cd
[root@localhost ~]# pwd
/Root
[root@localhost ~]#
One Linux command per day (3): pwd command