鍍金池/ 教程/ Linux/ pwd命令
which命令
ss命令
cp命令使用示例
ps命令
find命令
grep命令
scp命令
rmdir命令
df命令示例
less命令
du命令示例
chown命令示例
route命令
ping命令
more命令
mv命令
ln命令
mkdir命令
rm命令
find命令常用參數(shù)示例
cat命令
find命令-xargs參數(shù)
touch命令
traceroute命令
gzip命令示例
date命令
ls命令
vmstat命令
lsof命令
diff命令
head命令
watch命令
ifconfig命令
cd命令
tail命令
iostat命令
chgrp命令示例
free命令
find命令-exec參數(shù)
tar命令打包解壓示例
cal命令
at命令
netstat命令
wc命令
chmod命令示例
pwd命令
top命令詳解示例
crontab命令(Linux定時(shí)任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

pwd命令

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)的確切位置。

1.命令格式

pwd [選項(xiàng)]

2.命令功能

查看”當(dāng)前工作目錄“的完整路徑

3.常用參數(shù)

一般情況下不帶任何參數(shù),但如果目錄是鏈接時(shí):
格式:pwd -P 顯示出實(shí)際路徑,而非使用連接(link)路徑。

4.常用實(shí)例

實(shí)例1:用 pwd 命令查看默認(rèn)工作目錄的完整路徑

pwd

執(zhí)行和輸出:

yiibai@ubuntu:~$ pwd
/home/yiibai
yiibai@ubuntu:~$

實(shí)例2:使用 pwd 命令查看指定文件夾

pwd

執(zhí)行和輸出:

yiibai@ubuntu:~$ cd /usr/local/src/
yiibai@ubuntu:/usr/local/src$ pwd
/usr/local/src
yiibai@ubuntu:/usr/local/src$

實(shí)例3:pwd -P

目錄連接鏈接時(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]#

實(shí)例4:/bin/pwd

/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$

實(shí)例5:當(dāng)前目錄被刪除了,而pwd命令仍然顯示那個(gè)目錄

執(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:~$

上一篇:chmod命令示例下一篇:less命令