I am using Ubuntu 11.10 and in terminal I want to enter the following folder:

cd Milano, Torino (Jan)-Compressed

And it does not work! How should I write the command cd to enter this directory?

link|improve this question

59% accept rate
feedback

4 Answers

up vote 15 down vote accepted

That command is ambiguous because spaces are normally used to separate arguments. cd does not know what you want to do but you have two possibilities to solve it:

Either you "mask" the spaces (and all other special characters) so that the terminal knows you mean the space as a character and not as a separator:

cd Milano\,\ Torino\ \(Jan\)-Compressed

Or you put your folder name or path into quotes:

cd "Milano, Torino (Jan)-Compressed"
link|improve this answer
feedback

Write it as

cd 'Milano, Torino (Jan)-Compressed'

Otherwise it treats Milano, as the folder name. This happens because of the spaces in the name of the folder.

Alternatively escape a few of the special characters...

cd Milano\,\ Torino\ \(Jan\)-Compressed/
link|improve this answer
7  
You can also use Tab for auto-completion inside the double quotes to auto-escape double-quotes within the filename. – htorque Feb 5 at 12:06
2  
Note that double quotes won't help you cd into a directory named $money, for example. You'd need to write '$money' or \$money. – Dietrich Epp Feb 5 at 20:22
3  
I think generally single quotes are more explicit, and a better standard. Both work, but single quotes work more often and say "exactly as you see it". – isaaclw Feb 5 at 21:50
@isaaclw Thanks, I agree! Edited. – Prateek Feb 6 at 14:14
feedback

A little tip tab completion :)

  1. Just type the first letter e.g cd Mi and press Tab. Terminal will help you completing the rest words.

Another way drag and drop

  1. If you can see the directory and if you want to access it using terminal, just type: cd first and then drag and drop the directory on the terminal and hit enter.
link|improve this answer
2  
Got to love tab completion <3 – Rinzwind Feb 5 at 15:39
While the accepted answer is technically correct, in practice you're going to want tab-completion so you don't have to do all that escaping. – phasetwenty Feb 9 at 21:32
feedback

If this directory is in your home folder then type:

cd "Milano, Torino (Jan)-Compressed"

else give absolute path:

cd "/…/…/Milano, Torino (Jan)-Compressed"

if there is a double quote in file name then escape that with \"

link|improve this answer
If you start a path with a leading forward slash, it goes from root. You might want to remove that. – isaaclw Feb 5 at 21:52
@isaaclw That is why he filed it as an absolute path :P – dunsmoreb Feb 6 at 1:16
Ah, that's three dots, indicating a "variable" folder. I assumed it was two dots, indicating "parent folder". Apologies. – isaaclw Feb 6 at 3:43
feedback

Your Answer

 
or
required, but never shown

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