55

I can't figure out how to write the path of a folder that includes spaces in its name (in Terminal).

I tried:

cd /path/path/path/"A Folder"/file

cd /path/path/path/'A Folder/file

cd /path/path/path/A_Folder/file

but they all return the error through the terminal:

[command]: cannot access '/path/path/path/A Folder/file' No such a file or directory 

I can still access it through steps like so:

cd /home
cd user
cd Desktop
cd "Bash Programming"
bash Example
Zanna
  • 69,223
  • 56
  • 216
  • 327
Elian Kamal
  • 761
  • 2
  • 7
  • 11
  • 1
    Please post the **exact** command you're using - not a generic `/path/path/A Folder`. Since the error message includes the full path (with space) it's unlikely to be an issue with the space - more likely you are making an error in the path itself. – steeldriver Sep 30 '14 at 13:40
  • 4
    The first one (`cd /path/path/path/"A Folder"/file`) should work. – glenn jackman Sep 30 '14 at 14:00

4 Answers4

85

You can enclose the whole path by double-quotes ("), single-quote (') or escape the space character using a backslash (\) :

cd "/path/path/path/A Folder/file"
cd '/path/path/path/A Folder/file'
cd /path/path/path/A\ Folder/file
Benoit
  • 7,497
  • 1
  • 24
  • 34
10

Either quote the entire name:

cd "/path/path/path/A Folder/file"

or escape just the strange characters (space, in this case) using a backslash.

cd /path/path/path/A\ Folder/file

Another thing to try, is using tab completion:

cd /home/user/Desktop/Bas

Then press the TAB key, this should complete it to:

cd /home/user/Desktop/Bash\ Programming/

Then you can type the rest of the path.

roadmr
  • 33,892
  • 9
  • 80
  • 93
  • When I try using the tab completion, it just stops before the 'space' and doesn't auto-complete further. Is there some setting in the .bashrc that enables this feature? – Lakshya Goyal Dec 23 '21 at 18:14
6

Have you tried this?

cd Bash\ Programming

Or

/path/path/path/A\ Folder/file
ararog
  • 191
  • 5
5

either put all or partial path in single or double quote or escape space with backslash.
Eg:

cd /path\ to\ folder  
cd '/path to folder'
αғsнιη
  • 35,092
  • 41
  • 129
  • 192
totti
  • 6,768
  • 4
  • 38
  • 48