How to cd into a directory with space in the name?

前端 未结 14 2177
独厮守ぢ
独厮守ぢ 2020-11-27 05:30

I\'m attempting to get into the directory /cygdrive/c/Users/my dir/Documents:

$ DOCS=\"/cygdrive/c/Users/my\\ dir/Documents\"

$ echo $DOCS
/cyg         


        
相关标签:
14条回答
  • 2020-11-27 06:18

    Cygwin has issue recognizing space in between the PC name. So to solve this, you have to use "\" after the first word then include the space, then the last name.

    such as ".../my\ dir/"

    $ cd /cygdrive/c/Users/my\ dir/Documents
    

    Another interesting and simple way to do it, is to put the directory in quotation marks ("")

    e.g run it as follows:

    $ cd c:
    $ cd Users
    $ cd "my dir"
    $ cd Documents
    

    Hope it works?

    0 讨论(0)
  • 2020-11-27 06:18

    As an alternative to using quotes, for a directory you want to go to often, you could use the cdable_vars shell option:

    shopt -s cdable_vars
    docs='/cygdrive/c/Users/my dir/Documents'
    

    Now, to change into that directory from anywhere, you can use

    cd docs
    

    and the shell will indicate which directory it changed to:

    $ cd docs
    /cygdrive/c/Users/my dir/Documents
    
    0 讨论(0)
提交回复
热议问题