What is the use of the pwd command in Linux?

  

The Linux pwd command is mainly used to print the working path of the current working directory. If you want to use the pwd command, you should know the usage of the pwd command. The following small series will introduce you to the pwd command in Linux.

not sure when the current location, it will use pwd to determine the exact location of the current directory in the file system.

1. Command format:

pwd [options]

2. Command function:

View the full path of the current working directory <quo;

3. Common parameters:

Normally without any parameters

If the directory is linked:

Format: pwd -P shows the actual path instead of using the link (link )path.

4. Common examples:

Instance 1: Use the pwd command to view the full path of the default working directory

Command:

pwd

Output:

[root@localhost ~]# pwd

/root

[root@localhost ~]#

Instance 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 the directory is linked, pwd -P shows the actual path instead of 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 [options]

Options:

-L When the directory is linked, the 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< Br>

/etc/rc.d/init.d

[root@localhost init.d]# /bin/pwd -L

/etc/init.d

[root@localhost init.d]#

Instance 5: 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 “. . <quo; with matching i-node

[root@localhost removed]# cd

[root@localhost ~]# pwd

/root

[ Root@localhost ~]#

The above is the usage of the Linux pwd command. When you are not sure about the exact location of the current directory, you can use the pwd command to view the path. Try it out.

Copyright © Windows knowledge All Rights Reserved