Linux中用 pwd 指令來檢視”目前工作目錄“的完整路徑。 簡單得說,每當你在終端進行操作時,你都會有一個目前工作目錄。在不太确定目前位置時,就會使用pwd來判定目前目錄在檔案系統内的确切位置。
1.指令格式:
pwd [選項]
2.指令功能:
檢視”目前工作目錄“的完整路徑
3.常用參數:
一般情況下不帶任何參數
如果目錄是連結時:
格式:pwd -P 顯示出實際路徑,而非使用連接配接(link)路徑。
4.常用執行個體:
執行個體1:用 pwd 指令檢視預設工作目錄的完整路徑,指令:
pwd
輸出:
[[email protected] ~]# pwd
/root
[[email protected] ~]#
執行個體2:使用 pwd 指令檢視指定檔案夾,指令:
pwd
輸出:
[[email protected] ~]# cd /opt/soft/
[[email protected] soft]# pwd
/opt/soft
[[email protected] soft]#
執行個體三:目錄連接配接連結時,pwd -P 顯示出實際路徑,而非使用連接配接(link)路徑;pwd顯示的是連接配接路徑,指令:
pwd -P
輸出:
[[email protected] soft]# cd /etc/init.d
[[email protected] init.d]# pwd
/etc/init.d
[[email protected] init.d]# pwd -P
/etc/rc.d/init.d
[[email protected] init.d]#
執行個體4:/bin/pwd,指令:
/bin/pwd [選項]
選項:-L 目錄連接配接連結時,輸出連接配接路徑;-P 輸出實體路徑
輸出:
[[email protected] init.d]# /bin/pwd
/etc/rc.d/init.d
[[email protected] init.d]# /bin/pwd --help
[[email protected] init.d]# /bin/pwd -P
/etc/rc.d/init.d
[[email protected] init.d]# /bin/pwd -L
/etc/init.d
[[email protected] init.d]#
執行個體五:目前目錄被删除了,而pwd指令仍然顯示那個目錄
輸出:
[[email protected] init.d]# cd /opt/soft
[[email protected] soft]# mkdir removed
[[email protected] soft]# cd removed/
[[email protected] removed]# pwd
/opt/soft/removed
[[email protected] removed]# rm ../removed -rf
[[email protected] removed]# pwd
/opt/soft/removed
[[email protected] removed]# /bin/pwd
/bin/pwd: couldn't find directory entry in “..” with matching i-node
[[email protected] removed]# cd
[[email protected] ~]# pwd
/root
[[email protected] ~]#