
在 中bash 4.4.12
說help cd
:
Options: -L force symbolic links to be followed: resolve symbolic links in DIR after processing instances of `..' -P use the physical directory structure without following symbolic links: resolve symbolic links in DIR before processing instances of `..' -e if the -P option is supplied, and the current working directory cannot be determined successfully, exit with a non-zero status -@ on systems that support it, present a file with extended attributes as a directory containing the file attributes
我很難理解這些詞,而且我的谷歌搜尋引擎也找不到任何東西。
cd -P
什麼時候會優先於 的例子是什麼cd
?cd -L
與標準有何不同cd
?- 怎麼可能無法成功確定工作目錄呢?
- 使用的例子是什麼
-@
?
答案1
這bash手冊給出了更多細節。
cd -P
確保你最終得到一條「真實」的路徑:$ cd /tmp $ mkdir -p a/b $ ln -s a/b b $ cd b $ pwd /tmp/b $ cd -P ../b $ pwd /tmp/a/b
使用意味著從到 的
-P
符號連結被取消引用。與is 的交互作用通常透過刪除前一個路徑元件(如果有)來處理;不是透過檢查磁碟上的路徑。如果您使用大量符號鏈接,這最終會變得非常混亂。b
a/b
..
..
cd -L
相當於預設的cd
。無法確定目前工作目錄是否已刪除:
$ cd /tmp $ mkdir -p c/d $ cd c/d $ rmdir ../d ../../c $ cd ..; echo $? cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory 0
v.
$ cd -Pe ..; echo $? cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory 1
我對此不太確定(我可以想像它會是什麼樣子,但 Bash 只是說「
cd
::-@
無效選項」;我的印像是這目前僅在 Solaris 上可用,它需要O_XATTR
)。