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.
EDIT
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
ls;
fi
}
$ 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.
Best Answer
You have three options:
""
)Creating the directory:
Method 1:
Method 2:
Method 3:
Based on your comment on the other answer: for accessing the file named, the escaping needs to be done as follows:
However, using TAB completion makes this process easier and avoids you having to escape the spaces manually.