Home  >  Article  >  Operation and Maintenance  >  How to use linux pwd command

How to use linux pwd command

WBOY
WBOYforward
2023-05-18 08:40:113951browse

Use the pwd command in Linux to view the full path of the "current working directory". Simply put, whenever you operate in the terminal, you will have a current working directory.
When you are not sure of the current location, pwd will be used to determine the exact location of the current directory in the file system.

1. Command format:
pwd [option]

2. Command function:
View the full path of the "current working directory"

3. Commonly used parameters:
Generally 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: Use the pwd command to view the full path of the default working directory
Command:
pwd
Output:

Copy code The code is as follows:

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

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

Copy code The code is as follows:

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

# Example 3: When connecting to a directory, pwd -p displays the actual path instead of using the link path; pwd The connection path shown is
Command:
pwd -p

Copy code The code is as follows:

[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]
Option:
-l When connecting to the directory, output the connection path
-p and output the physical path
Output:

Copy the code The code is as follows:

[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, but the pwd command still displays that directory

Copy code The code is as follows:

[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 ~]

#

The above is the detailed content of How to use linux pwd command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete