Linux中用pwd命令以絕對路徑的方式顯示用戶當前工作目錄。命令將當前目錄的全路徑名稱(從根目錄)寫入標准輸出。全部目錄使用/分隔。第一個/表示根目錄,最后一個目錄是當前目錄。執行pwd命令可立刻得知您目前所在的工作目錄的絕對路徑名稱。
1、命令格式:
pwd [選項]
2、命令功能:
查看“當前工作目錄”的完整路徑
3、命令參數:
一般情況下不帶任何參數
如果目錄是連接時:
格式:pwd -P顯示出實際路徑,而非使用鏈接(link)路徑。
4、命令實例:
實例1:用pwd命令查看默認工作目錄的完整路徑
命令:
pwd
輸出:
[root@localhost ~]# pwd
/root
[root@localhost ~]#
實例2:使用pwd命令查看當前工作目錄的完整路徑
命令:
pwd
輸出:
[root@localhost test3]# pwd
/root/test/test1/test2/test3
[root@localhost test3]#
實例3:查看鏈接目錄,顯示出實際路徑
命令:
pwd -P
輸出:
[root@localhost ~]# 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顯示的是連接路徑;pwd -P顯示的是實際路徑;
實例4:當命令pwd被別命名時,可用全路徑/bin/pwd來查看目錄
命令:
/bin/pwd [選項]
參數:
-L 目錄為鏈接時,輸出鏈接路徑
-P 輸出物理路徑
輸出:
[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]#
實例5:當前目錄被刪除了,而pwd命令仍然可以顯示那么目錄路徑
輸出:
[root@localhost tset6]# pwd
/root/test/test1/test2/test3/test4/test5/tset6
[root@localhost tset6]# rm -rf ../*
[root@localhost tset6]# pwd
/root/test/test1/test2/test3/test4/test5/tset6
[root@localhost tset6]# /bin/pwd
/bin/pwd: couldn't find directory entry in ‘..’ with matching i-node
[root@localhost tset6]#