The pwd command in linux USES elaboration

  • 2020-05-13 04:02:39
  • OfStack

Linux USES the pwd command to see the full path to the current working directory. Simply put, every time you operate on a terminal, you will have a working directory.
When in doubt, pwd is used to determine the exact location of the current directory within the file system.

1. Command format:
pwd [options]

2. Command functions:
See the full path to the current working directory

3. Common parameters:
1 normally without any parameters
If the directory is linked:
Format: pwd-P shows the actual path instead of using the join (link) path.

4. Common examples:
Example 1: view the full path to the default working directory with the pwd command
Command:
pwd
Output:


[root@localhost ~]# pwd
/root
[root@localhost ~]#

Example 2: view the specified folder using the pwd command
Command:
pwd
Output:


[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]#

Example 3: when a directory link is linked, pwd-P shows the actual path instead of using the link (link) 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 [option]
Options:
-L directory connection link when output connection path
-P outputs the 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]#

Example 5: the current directory has been 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 ~]#

That's the end of the PWD command. If you have any questions, please leave me a message


Related articles: