歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 每天一個Linux命令(7)pwd命令

每天一個Linux命令(7)pwd命令

日期:2017/3/3 13:49:01   编辑:Linux技術

pwd命令以絕對路徑的方式顯示用戶當前工作目錄。命令將當前目錄的全路徑名稱(從根目錄)寫入標准輸出。全部目錄使用/分隔。第一個/表示根目錄,最後一個目錄是當前目錄。[b] (1)用法介紹:[/b]

pwd[選項] [b] (2)選項參數:[/b]

一般情況下不帶任何參數 1) -L, --logical 顯示當前目錄

2) -P, --physical 顯示當前目錄的實際物理地址3) --help 幫助

4) --version 版本

[b] (3)功能:[/b] 執行pwd命令可立刻得知您目前所在的工作目錄的絕對路徑名稱。

[b] (4)運行實例:[/b] 1)[root@localhost Documents]# pwd 查看默認工作目錄的完整路徑,查看是否成功到達指定文件夾

[root@localhost sunjimeng]# mkdir Documents
[root@localhost sunjimeng]# cd ../../
[root@localhost /]# cd /home/sunjimeng/Documents
[root@localhost Documents]# pwd
/home/sunjimeng/Documents
[root@localhost Documents]#
2)[sunjimeng@localhost init.d]$ pwd -P 目錄連接鏈接時,pwd -P 顯示出實際物理路徑,pwd顯示連接路徑

[sunjimeng@localhost mail]$ cd /
[sunjimeng@localhost /]$ cd etc
[sunjimeng@localhost etc]$ cd init.d
[sunjimeng@localhost init.d]$ pwd
/etc/init.d
[sunjimeng@localhost init.d]$ pwd -P
/etc/rc.d/init.d
[sunjimeng@localhost init.d]$
3)[sunjimeng@localhost init.d]$ pwd -L 與pwd命令具有一樣的功能 顯示當前目錄的連接路徑

[sunjimeng@localhost /]$ cd etc/init.d
[sunjimeng@localhost init.d]$ pwd
/etc/init.d
[sunjimeng@localhost init.d]$ pwd -L
/etc/init.d
[sunjimeng@localhost init.d]$
4)[sunjimeng@localhost /]$ man pwd

PWD(1)                           User Commands                          PWD(1)

NAME
       pwd - print name of current/working directory

SYNOPSIS
       pwd [OPTION]...

DESCRIPTION
       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
5)/bin/pwd同pwd的用法一樣:

/bin/pwd [選項] 選項:

-L 目錄連接鏈接時,輸出連接路徑 -P 輸出物理路徑

[root@localhost init.d]# cd /
[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 -L
/etc/init.d
[root@localhost init.d]# /bin/pwd
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd -L
/etc/init.d
[root@localhost init.d]# /bin/pwd -P
/etc/rc.d/init.d
如果cd命令是逐級進入的化,區分連接路徑和實際路徑就沒有意義了:

[root@localhost init.d]# cd /                      //無論什麼命令,輸出的工作路徑都是/etc/rc.d/unit.d
[root@localhost /]# cd etc/rc.d/init.d
[root@localhost init.d]# pwd
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd
/etc/rc.d/init.d
[root@localhost init.d]# pwd -L
/etc/rc.d/init.d
[root@localhost init.d]# pwd -P
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd -L
/etc/rc.d/init.d
[root@localhost init.d]# /bin/pwd -P
/etc/rc.d/init.d
6)/bin/pwd與pwd命令的區別:(當前目錄被刪除了,而pwd命令仍然顯示那個目錄,而/bin/pwd則不會)

[root@localhost init.d]# cd /
[root@localhost /]# cd /home/sunjimeng/Documents
[root@localhost Documents]# mkdir removed
[root@localhost Documents]# ls -l
總用量 0
drwxr-xr-x. 2 root root 6 5月   4 07:29 removed
[root@localhost Documents]# cd removed
[root@localhost removed]# rmdir ../removed -rf          //這裡犯了一個錯誤,rmdir沒有rf選項參數,rm ../removed -rf等價於 rmdir ../removed
rmdir:無效選項 -- r
Try 'rmdir --help' for more information.
[root@localhost removed]# rmdir ../removed
[root@localhost removed]# pwd
/home/sunjimeng/Documents/removed
[root@localhost removed]# /bin/pwd
/bin/pwd: 在匹配的inode ".." 上找不到目錄入口      //這裡的結果表明了他們的區別
[root@localhost removed]# cd ../
[root@localhost Documents]# ll
總用量 0
[b] (5)其它[/b]

軟鏈接與硬鏈接的區別(講解): Linux 軟連接與硬連接

對於一個文件來說,有唯一的索引接點與之對應,而對於一個索引接點號,卻可以有多個文件名與之對應。因此,在磁盤上的同一個文件可以通過不同的路徑去訪問該文件。注意在Linux下是一切皆文件的啊,文件夾、新加的硬盤 ...都可以看著文件來處理的啊。 連接有軟連接和硬連接(hard link)之分的,軟連接(symbolic link)又叫符號連接。符號連接相當於Windows下的快捷方式。

參考:http://www.linuxidc.com/Linux/2014-12/111056.htm

Copyright © Linux教程網 All Rights Reserved