In a Linux hierarchy, users can create a new directory using the mkdir command in any given directory, or you can use the CD command to convert from one directory to another. However, there is no prompt to tell the user which directory is currently in. To know the current directory, you can use the PWD command, which displays the entire path name.
Name
Print Working Directory
Use
Displays the path name of the working directory.
Grammar
PWD [-l |-p]
Describe
The PWD command writes the full path name (from the root directory) of the current directory to standard output. All directories are separated by/(slash). The first/represents the root directory, and the last directory is the current directory.
Sign
-l– Display Logical Path
-p– Show Physical Path
Example:
The code is as follows |
Copy Code |
[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]# |
To view a specified folder using the PWD command
Command:
Pwd
Output:
The code is as follows |
Copy Code |
[Root@localhost ~]# cd/opt/soft/ [Root@localhost soft]# pwd /opt/soft [Root@localhost soft]# |
The current directory is deleted and the PWD command still displays that directory
Output:
code is as follows |
copy code |
[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 ~]# |