Linux common commands: pwd command

  Use the pwd command in Linux to view the full path of the "current working directory". Simply put, whenever you do something in the terminal, you have a current working directory. When not sure about 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 of the "current working directory"

3. Common parameters:

Normally without any parameters

If the directory is a link:

Format: pwd -P   displays the actual path instead of using the link path. 

4. Common examples:

Example 1: View the full path of the default working directory with the pwd command

Order:

pwd 

output:

[root@localhost ~]# pwd

/root

[root@localhost ~]#

 

Example 2 : Use the pwd command to view the specified folder

Order:

pwd

output:

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

[root@localhost soft]# pwd 

/opt/soft

[root@localhost soft]#

Example 3: When a directory is linked, pwd -P displays the actual path instead of using the link path; pwd displays the link path

Order:

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

Order:

/bin/pwd [ options ]

Options:

-L When the directory is linked, output the link 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]#

Example 5: The current directory is deleted, but 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 ~]#

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325120279&siteId=291194637