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

前端 未结 14 2176
独厮守ぢ
独厮守ぢ 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:03

    Why not put the following in your .cshrc (or .bashrc, or whatever your default shell is):

    alias mydoc 'cd "/cygdrive/c/Users/my dir/Documents"'
    

    First time you do this, you have to do

    source .cshrc
    

    to update the shell with this new alias, then you can type

    mydoc
    

    anytime you want to cd to your directory.

    Laziness is the mother of invention...

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

    If you want to move from c:\ and you want to go to c:\Documents and settings, write on console: c:\Documents\[space]+tab and cygwin will autocomplete it as c:\Documents\ and\ settings/

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

    Instead of:

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

    Try:

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

    This should work on any POSIX system.

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

    ok i spent some frustrating time with this problem too. My little guide.

    Open desktop for example. If you didnt switch your disc in cmd, type:

    cd desktop

    Now if you want to display subfolders:

    cd, make 1 spacebar, and press tab 2 times

    Now if you want to enter directory/file with SPACE IN NAME. Lets open some file name f.g., to open it we need to type:

    cd file\ name

    p.s. notice this space after slash :)

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

    try

    DOCS="/cygdrive/c/Users/my\ dir/Documents";
    
    cd "$DOCS"
    
    0 讨论(0)
  • 2020-11-27 06:14

    Use the backslash symbol to escape the space

    C:\> cd my folder
    

    will be

     C:\> cd my\folder 
    
    0 讨论(0)
提交回复
热议问题