Linux中用 pwd
命令來檢視」當前工作目錄「的完整路徑。簡單得說,每當我們在終端進行操作時,都會有一個當前工作目錄。
在不太確定當前位置時,就會使用pwd
來顯示當前目錄在檔案系統內的確切位置。
pwd [選項]
檢視」當前工作目錄「的完整路徑
一般情況下不帶任何引數,但如果目錄是連結時:
格式:pwd -P
顯示出實際路徑,而非使用連線(link)路徑。
pwd
執行和輸出:
yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$
pwd
執行和輸出:
yiibai@ubuntu:~$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ pwd
/usr/local/src
yiibai@ubuntu:/usr/local/src$
目錄連線連結時,pwd -P
顯示出實際路徑,而非使用連線(link)路徑;pwd顯示的是連線路徑。
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]#
/bin/pwd [選項]
選項:
-L
目錄連線連結時,輸出連線路徑-P
輸出物理路徑執行和輸出:
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 [email protected]
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$
執行和輸出:
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:~$