Ubuntu Linux 15.10 - 我刚注意到cd
这看起来有点奇怪。
我试过了:
man cd
在cmd线上,我回来了
No manual entry for cd
我试图在
上找到文档cd -
在最后一个目录和当前目录之间翻转非常方便
和cd --
似乎是
的别名cd ~
我是否遗漏了一些非常明显的内容,或者手册页应该存在?
答案 0 :(得分:12)
cd
不是命令,它内置于shell中。这是必要的,因为您当前的工作目录由PWD
或"打印工作目录"之后命名的pwd
环境变量控制。命令。
子进程无法更改父进程的环境变量。因此,如果您的shell运行/bin/cd
并更改了PWD
,那么它只会影响/bin/cd
及其运行的任何内容。它不会改变shell PWD
。
某些系统(如OS X和CentOS)将cd
手册页映射到builtin
,其中列出了所有shell内置函数,并告诉您应该查看shell的手册页
您可以使用echo $SHELL
检查自己的shell,可能是bash
。
答案 1 :(得分:5)
cd
是内置的shell命令。
您可以使用
在Bash上打开cd
的帮助页面
$ help cd
目前显示的内容(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.
不幸的是,它没有回答你的问题。但是是文档。
您可以使用
进行操作$ man builtins
它会打开我的默认查看器less
的许多帮助页面。我可以通过按/
键找到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.
从头到尾查找关于第七行的-
参数。
请注意,没有--
参数 - 这似乎意味着它实际上忽略了它。
答案 2 :(得分:-2)
bash手册页的相关摘录,内容涉及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.