bash cd 的选项示例,例如: cd -Pe@ $directory

Tom*_*ale 7 bash cd-command

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
Run Code Online (Sandbox Code Playgroud)

我很难理解这些词,而且我的 google-fu 无法提出任何内容。

  1. 什么时候cd -P会被首选的例子是什么cd
  2. 如何为cd -L标准不同cd
  3. 怎么可能无法成功确定工作目录?
  4. 什么是使用的例子-@

Ste*_*itt 5

猛砸手册给出了更详细一点。

  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
    
    Run Code Online (Sandbox Code Playgroud)

    Using-P表示来自bto的符号链接a/b被取消引用。与..is的交互..通常是通过删除前一个路径组件来处理的,如果有的话;不是通过检查磁盘上的路径。如果您使用大量符号链接,这最终会变得非常混乱。

  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
    
    Run Code Online (Sandbox Code Playgroud)

    v.

    $ cd -Pe ..; echo $?
    cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
    1
    
    Run Code Online (Sandbox Code Playgroud)
  4. 这我不知道(我能想象它会是什么样子,但击只是说“ cd-@:无效选项”;我得到的印象,这是目前仅在Solaris上可用的,它需要O_XATTR)。