Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory called "foo bar baz blob". How can I

$ cd "foo bar baz blob"

I have tried with quoting (" and ') and with escaping the blanks (\ ). It does not work. Tab-completion does not work either.

I also have to issue commands with filename arguments that contain spaces. How do I do that? Even MidnightCommander (mc) fails in doing this.


Over one year later, I finally found the source of my problem. I have overloaded the builtin cd with a function that automatically lists the files of the changed directory:

$ type cd
cd ist eine Funktion.
cd () 
    if builtin cd $1; then

$ cd Interner\ Speicher/
bash: cd: Interner: Datei oder Verzeichnis nicht gefunden

$ builtin cd Interner\ Speicher/

$ pwd
/run/user/1000/gvfs/mtp:host=%5Busb%3A002%2C018%5D/Interner Speicher

$ ls
Alarms   DCIM      Movies  Notifications  Podcasts   SmsContactsBackup
Android  Download  Music   Pictures   Ringtones

The solution is easy: I just have to put double quotes around the $1:

if builtin cd "$1"; then

Ooof. Thank you.

share|improve this question
Quoting or escaping should work. Is the foo bar baz blob directory within your current directory? Check with ls - if not you will need to add the absolute or relative path to the directory name. – steeldriver Jan 11 '14 at 20:01
Is the foo bar baz blob folder in the home directory? By default, terminal opens 'in' the home directory, so the command would not work otherwise.This is how it should be escaped in terminal: cd foo\ bar\ baz\ blob/. – Wilf Jan 11 '14 at 20:04
do ls in the directory and edit it in your question so we can see exactly what characters we are dealing with. – Braiam Jan 11 '14 at 20:56
Perhaps did you get these files from a mac?… – Mateo Jan 11 '14 at 21:26
up vote 2 down vote accepted

You have three options:

  • Escape the spaces using a backslash character
  • Wrap the directory name in double-quotes ("")
  • Use TAB completion

Creating the directory:

user@pc:~/testfolder$ ls -l
total 0
user@pc:~/testfolder$ mkdir "foo bar baz blob"
user@pc:~/testfolder$ ls
foo bar baz blob

Method 1:

user@pc:~/testfolder$ cd foo\ bar\ baz\ blob/
user@pc:~/testfolder/foo bar baz blob$ echo "This works"
This works

Method 2:

user@pc:~/testfolder$ cd "foo bar baz blob"/
user@pc:~/testfolder/foo bar baz blob$ echo "This works, too"
This works, too

Method 3:

user@pc:~/testfolder$ cd foo<TAB><ENTER>

Based on your comment on the other answer: for accessing the file named, the escaping needs to be done as follows:

Eric\ Burdon\ -\ Starportrait\ -\ CD\ 1\ \(flac\).cue foo\ bar\ baz\ blob/

However, using TAB completion makes this process easier and avoids you having to escape the spaces manually.

share|improve this answer
method 3 would be my method 1 :D [tab] seems to work better (it will also resolve unprintable chars and will also do different enconding correctly) – Rinzwind Jan 11 '14 at 21:08
I forgot to mention that I changed the directory's name into "EricBurdonStarportrait" with the Thunar file manager, so that the problem left was to use the filenames as arguments on the command line. – ubuplex Jan 12 '14 at 11:20

I just created the same folder, in /home/abed, used tab completion, and it worked. See image below. If the folder was created at a different location, you'll have to navigate to that location before you can CD into your folder.

enter image description here

That's also OK. See image

enter image description here

share|improve this answer
What wrong with the answer? – Mitch Jan 11 '14 at 20:11
OK, Hmmm. Then I think the problem is that there is a "-" in the directory name, e.g., "The Rolling Stones - Sticky Fingers - 1971". Escaping by "\-" does not work. – ubuplex Jan 11 '14 at 20:36
Then the problem is in a "(", which is also in the filename. The file I want to process is "Eric Burdon - Starportrait - CD 1 (flac).cue". Here, escaping ( and ) does not work: shntool [split]: error: need exactly one file to process – ubuplex Jan 11 '14 at 20:52
@ubuplex is a file or a directory? – Braiam Jan 11 '14 at 20:57

Quote your filename with single quotes.

cd 'foo bar baz literal string'

In the shell, nothing is interpreted inside single quotes so you should be safe from having unusual characters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.