What does 'cd -' stand for?

后端 未结 8 1189
星月不相逢
星月不相逢 2020-12-13 05:41

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.

相关标签:
8条回答
  • 2020-12-13 05:51

    From the man found here : http://ss64.com/bash/cd.html

    Quickly get back
    $ cd - 
    
    0 讨论(0)
  • 2020-12-13 05:55

    cd - brings you back to the last directory.

    $ cd ~/Desktop
    $ pwd
    /Users/daknok/Desktop
    $ cd /
    $ pwd
    /
    $ cd -
    $ pwd
    /Users/daknok/Desktop
    
    0 讨论(0)
  • 2020-12-13 06:04

    If a single dash is specified as the argument, it will be replaced by the value of OLDPWD.

    The OLDPWD is set by cd command and it is the previous working directory.

    0 讨论(0)
  • 2020-12-13 06:05

    “ Current Directory “ Is what the bash cd terminal command means. It means “ keep me in this directory “

    0 讨论(0)
  • 2020-12-13 06:09

    cd - returns to the directory you were previously.

    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 -

    0 讨论(0)
  • 2020-12-13 06:09

    cd - bring you back to the last directory you were. e.g.

    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'

    0 讨论(0)
提交回复
热议问题