Linux 'cd -' 代表什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9740298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does 'cd -' stand for?
提问by AppleGrew
In a bash shell script today I noticed the below command at the end of the script. I know what is cd
but I am unaware of the significance of a dash after it.
在今天的 bash shell 脚本中,我注意到脚本末尾的以下命令。我知道是什么,cd
但我不知道在它之后划线的重要性。
cd -
What does this mean? Google naively truncates the -
so I am unable to find its answer.
这是什么意思?谷歌天真地截断了-
所以我无法找到它的答案。
采纳答案by Sandro Munda
If a single dash is specified as the argument, it will be replaced by the value of OLDPWD
.
如果将单个破折号指定为参数,它将被 的值替换OLDPWD
。
The OLDPWD
is set by cd
command and it is the previous working directory.
在OLDPWD
被设定cd
的命令,这是以前的工作目录。
回答by Marcelo Diniz
cd -
returns to the directory you were previously.
cd -
返回到您之前所在的目录。
For instance:
例如:
marcelo@marcelo:~$ cd /opt marcelo@marcelo:/opt$ cd /usr/bin marcelo@marcelo:/usr/bin$ cd - /opt marcelo@marcelo:/opt$
I was in /opt, changed to /usr/bin, and then went back to /opt with cd -
我在/opt,改成/usr/bin,然后又回到/opt cd -
回答by Cfreak
cd -
returns to the previous directory you were in.
cd -
返回到您所在的上一个目录。
Say I'm in /usr/
and I type cd /var/local/someplace/else
说我在/usr/
,我打字cd /var/local/someplace/else
Then I use cd -
I'll return to /usr
然后我用cd -
我会回到/usr
回答by Cfreak
cd -
brings you back to the last directory.
cd -
带您回到上一个目录。
$ cd ~/Desktop
$ pwd
/Users/daknok/Desktop
$ cd /
$ pwd
/
$ cd -
$ pwd
/Users/daknok/Desktop
回答by Michael Laffargue
From the man found here : http://ss64.com/bash/cd.html
从这里找到的人:http: //ss64.com/bash/cd.html
Quickly get back
$ cd -
回答by phoxis
From the manual
从手册
An argument of - is equivalent to $OLDPWD. 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
- 的参数等效于 $OLDPWD。如果使用 CDPATH 中的非空目录名,或者如果 - 是第一个参数,并且目录更改成功,则新工作目录的绝对路径名将写入标准输出。如果目录更改成功,则返回值为真;否则为假
Therefore the -
is equivalent to the $OLDPWD
, which holds the last directory which the shell was in, and is set by the previous cd
invocation.
因此 the-
相当于$OLDPWD
,它保存了 shell 所在的最后一个目录,并由前一次cd
调用设置。
回答by Jie Zhang
cd - bring you back to the last directory you were. e.g.
cd - 带你回到上一个目录。例如
cd ~/Documents
cd ~
cd /
Now you are in '/', and if you run 'cd -' you will be in '~'. BTW, run 'cd -' once again, you will return to '/' but not '~/Documents'
现在你在'/',如果你运行'cd -',你会在'~'。顺便说一句,再次运行 'cd -',您将返回 '/' 而不是 '~/Documents'
回答by TheHessian
“ Current Directory “ Is what the bash cd terminal command means. It means “ keep me in this directory “
“当前目录”是 bash cd 终端命令的意思。意思是“让我留在这个目录中”