简体   繁体   English

没有 cd 命令的手册页

[英]No man page for the cd command

Ubuntu Linux 15.10 - I just noticed that there is no man page for cd Ubuntu Linux 15.10 - 我刚刚注意到cd没有手册页

This seems a bit strange.这似乎有点奇怪。

I tried:我试过:

man cd

at the cmd line and I get back在 cmd 行,我回来了

No manual entry for cd

I was trying to find documentation on我试图找到有关的文档

cd -

which is super-handy for flipping between the last dir and the current dir这对于在最后一个目录和当前目录之间翻转非常方便

and cd --cd --

which seems to be an alias for这似乎是一个别名

cd ~

Am I missing something very obvious here, or should the man page be present?我在这里遗漏了一些非常明显的东西,还是应该提供手册页?

cd is not a command, it's built into your shell. cd不是命令,它内置于您的 shell 中。 This is necessary because your current working directory is controlled by the PWD environment variable named after the pwd or "print working directory" command.这是必要的,因为您当前的工作目录由以pwd或“打印工作目录”命令命名的PWD环境变量控制。

The environment variables of a parent process cannot be changed by a child process.子进程不能更改父进程的环境变量。 So if your shell ran /bin/cd which changed PWD it would only affect /bin/cd and anything it ran.因此,如果您的 shell 运行/bin/cd更改了PWD它只会影响/bin/cd及其运行的任何内容。 It would not change the shell's PWD .它不会改变外壳的PWD

Some systems, like OS X and CentOS, map the cd man page to builtin which lists all the shell built ins and lets you know you should look at your shell's man page.某些系统,如 OS X 和 CentOS,将cd手册页映射到builtin ,其中列出了所有 shell 内置程序,并让您知道应该查看 shell 的手册页。

You can check what shell you have with echo $SHELL , it's probably bash .您可以使用echo $SHELL检查您拥有的echo $SHELL ,它可能是bash

cd is a builtin shell command. cd是一个内置的 shell 命令。

$ type cd
cd is a shell builtin

You can open a help page for cd on Bash with您可以在 Bash 上打开cd的帮助页面

$ help cd

Which currently shows (Ubuntu 16.04):目前显示(Ubuntu 16.04):

$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
    Change the shell working directory.

    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.

    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.

    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.

    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

    The default is to follow symbolic links, as if `-L' were specified.
    `..' is processed by removing the immediately previous pathname component
    back to a slash or the beginning of DIR.

    Exit Status:
    Returns 0 if the directory is changed, and if $PWD is set successfully when
    -P is used; non-zero otherwise.

Unfortunately, it does not answer your questions.不幸的是,它没有回答您的问题。 There is documentation that does, however.文档,做不过来。

You can get to it with你可以用

$ man builtins

It opens many pages of help with less , my default viewer.它使用我的默认查看器less打开许多帮助页面。 I can find the help for cd by pressing the / key, then typing cd , then Enter , and pressing n twice gets me to the third instance of the substring, and the help, which reads:我可以通过按/键找到 cd 的帮助,然后输入cd ,然后Enter ,然后按两次n可以找到子字符串的第三个实例,帮助内容如下:

   cd [-L|[-P [-e]] [-@]] [dir]
          Change  the  current  directory to dir.  if dir is not supplied,
          the value of the HOME shell variable is the default.  Any  addi‐
          tional arguments following dir are ignored.  The variable CDPATH
          defines the search path for the directory containing  dir:  each
          directory  name  in  CDPATH  is  searched  for dir.  Alternative
          directory names in CDPATH are separated by a colon (:).  A  null
          directory  name  in CDPATH is the same as the current directory,
          i.e., ``.''.  If dir begins with a slash (/), then CDPATH is not
          used.  The  -P  option  causes  cd to use the physical directory
          structure by resolving symbolic links while traversing  dir  and
          before processing instances of .. in dir (see also the -P option
          to the set builtin command); the -L option forces symbolic links
          to  be followed by resolving the link after processing instances
          of .. in dir.  If .. appears in dir, it is processed by removing
          the  immediately previous pathname component from dir, back to a
          slash or the beginning of dir.  If the  -e  option  is  supplied
          with  -P,  and  the current working directory cannot be success‐
          fully determined after a successful directory  change,  cd  will
          return  an unsuccessful status.  On systems that support it, the
          -@ option presents the extended  attributes  associated  with  a
          file  as  a directory.  An argument of - is converted to $OLDPWD
          before the directory change is attempted.  If a non-empty direc‐
          tory  name  from  CDPATH is used, or if - is the first argument,
          and the directory change is successful, the absolute pathname of
          the  new  working  directory  is written to the standard output.
          The return value is  true  if  the  directory  was  successfully
          changed; false otherwise.

Look for the - argument about the seventh line from the end:寻找关于从末尾开始的第七行的-参数:

An argument of - is converted to $OLDPWD before the directory change is attempted.在尝试更改目录之前, -的参数被转换为$OLDPWD

Note that there is no -- argument - which seems to mean that it actually ignores it.请注意,没有--参数 - 这似乎意味着它实际上忽略了它。

relevant excerpt from the bash man page covering usage of cd - bash 手册页的相关摘录,涵盖了cd -使用cd -

       cd [-L|[-P [-e]] [-@]] [dir]
              Change the current directory to dir. 
              ...

              An argument of  -
              is  converted to $OLDPWD before the directory change is attempted.  If a non-
              empty directory name from CDPATH is used, or if - is the first argument,  and
              the  directory change is successful, the absolute pathname of the new working
              directory is written to the standard output.  The return value is true if the
              directory was successfully changed; false otherwise.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM