bash cd 選項範例,例如: cd -Pe@ $directory

bash cd 選項範例,例如: cd -Pe@ $directory

在 中bash 4.4.12help 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

我很難理解這些詞,而且我的谷歌搜尋引擎也找不到任何東西。

  1. cd -P什麼時候會優先於 的例子是什麼cd
  2. cd -L與標準有何不同cd
  3. 怎麼可能無法成功確定工作目錄呢?
  4. 使用的例子是什麼-@

答案1

bash手冊給出了更多細節。

  1. 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 的交互作用通常透過刪除前一個路徑元件(如果有)來處理;不是透過檢查磁碟上的路徑。如果您使用大量符號鏈接,這最終會變得非常混亂。ba/b....

  2. cd -L相當於預設的cd

  3. 無法確定目前工作目錄是否已刪除:

    $ 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
    
  4. 我對此不太確定(我可以想像它會是什麼樣子,但 Bash 只是說「cd::-@無效選項」;我的印像是這目前僅在 Solaris 上可用,它需要O_XATTR)。

相關內容