每(mei)天(tian)一個linux命令(3):pwd命令
Linux中用 pwd 命令來查看”當前工作目錄“的完整路徑。 簡單得說,每當你在終端進行操作時,你都會有一個當前工作目錄。
在不太確定當前位置時,就會使用pwd來判(pan)定當前目錄在文件系統內(nei)的確切位置(zhi)。
1.命令(ling)格式:
pwd [選項]
2.命令功(gong)能:
查看”當前工作目錄“的完整路徑
3.常用參數:
一般情況下不帶(dai)任何參數
如果(guo)目錄(lu)是鏈接時:
格式:pwd -P 顯示出實際路徑,而非使用連接(link)路徑。
4.常用(yong)實例:
實例(li)1:用 pwd 命令查看默認工作目錄的完整路徑
命令(ling):
pwd
輸出:
[root@localhost ~]# pwd
/root
[root@localhost ~]#
實例2:使用 pwd 命令查看指(zhi)定(ding)文件夾(jia)
命令:
pwd
輸出:
[root@localhost ~]# cd /opt/soft/
[root@localhost soft]# pwd
/opt/soft
[root@localhost soft]#
實例三:目錄連接鏈接時,pwd -P 顯示出實際路徑,而非使用連接(link)路徑;pwd顯示的是連接路徑
命(ming)令:
pwd -P
輸出(chu):
[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]#
實例4:/bin/pwd
命令:
/bin/pwd [選項]
選項:
-L 目(mu)錄連接鏈接時(shi),輸出連接(jie)路徑
-P 輸出物理(li)路徑
輸(shu)出:
[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]#
實例五:當前目錄被刪除了,而pwd命(ming)令(ling)仍然顯(xian)示那(nei)個目錄
輸出:
[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 ~]#
關注 熵減黑客 ,一起學習成長
