A Linux command a day (3): pwd command

post thumb
Devops
by Admin/ on 15 Sep 2021

A Linux command a day (3): pwd command


The pwd command is used in Linux to see the full path to the current working directory. Simply put, whenever you operate in the terminal, you will have a current working directory.

When you are not quite sure of the current location, you use pwd to determine exactly where the current directory is located on the file system.

1. Command format.

pwd [option]

2. Command function.

View the full path of the “current working directory”.

3. Common parameters.

Generally without any parameters

If the directory is linked.

Format: pwd -P Show 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.

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

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

Command: pwd

Output.

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

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]# pwd -P /etc/rc.d/init.d [root@localhost init.d]# `

Example 4: /bin/pwd

Command: /bin/pwd [options]

Options.

-L Output connection path when linking directory connections

-P Output 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, but the pwd command still shows 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 ~]#  

Reference:

www.cnblogs.com/peida/archive/2012/10/24/2737730.html

comments powered by Disqus