Linux中用 pwd
命令來(lái)查看”當(dāng)前工作目錄“的完整路徑。簡(jiǎn)單得說(shuō),每當(dāng)我們?cè)诮K端進(jìn)行操作時(shí),都會(huì)有一個(gè)當(dāng)前工作目錄。
在不太確定當(dāng)前位置時(shí),就會(huì)使用pwd
來(lái)顯示當(dāng)前目錄在文件系統(tǒng)內(nèi)的確切位置。
pwd [選項(xiàng)]
查看”當(dāng)前工作目錄“的完整路徑
一般情況下不帶任何參數(shù),但如果目錄是鏈接時(shí):
格式:pwd -P
顯示出實(shí)際路徑,而非使用連接(link)路徑。
pwd
執(zhí)行和輸出:
yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$
pwd
執(zhí)行和輸出:
yiibai@ubuntu:~$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ pwd
/usr/local/src
yiibai@ubuntu:/usr/local/src$
目錄連接鏈接時(shí),pwd -P
顯示出實(shí)際路徑,而非使用連接(link)路徑;pwd顯示的是連接路徑。
pwd -P
執(zhí)行和輸出:
[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]#
/bin/pwd [選項(xiàng)]
選項(xiàng):
-L
目錄連接鏈接時(shí),輸出連接路徑-P
輸出物理路徑執(zhí)行和輸出:
yiibai@ubuntu:/etc/init.d$ /bin/pwd
/etc/init.d
yiibai@ubuntu:/etc/init.d$ /bin/pwd --help
Usage: /bin/pwd [OPTION]...
Print the full filename of the current working directory.
-L, --logical use PWD from environment, even if it contains symlinks
-P, --physical avoid all symlinks
--help display this help and exit
--version output version information and exit
NOTE: your shell may have its own version of pwd, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
Report pwd bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'pwd invocation'
yiibai@ubuntu:/etc/init.d$ /bin/pwd -P
/etc/init.d
yiibai@ubuntu:/etc/init.d$ /bin/pwd -L
/etc/init.d
yiibai@ubuntu:/etc/init.d$
執(zhí)行和輸出:
yiibai@ubuntu:/etc/init.d$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ mkdir beremoved
yiibai@ubuntu:/usr/local/src$ cd beremoved/
yiibai@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
yiibai@ubuntu:/usr/local/src/beremoved$ rm ../beremoved/ -rf
yiibai@ubuntu:/usr/local/src/beremoved$ pwd
/usr/local/src/beremoved
yiibai@ubuntu:/usr/local/src/beremoved$ /bin/pwd
/bin/pwd: couldn't find directory entry in a€?..a€? with matching i-node
yiibai@ubuntu:/usr/local/src/beremoved$ cd
yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$