Reputation: 2551
I am trying to go to a directory whose file name has spaces between them in the Linux terminal. I tried doing this:
cd Magical Island
bash: cd: Magical: No such file or directory
As you can see, it didn't work
How can I make it work?
Upvotes: 1
Views: 11010
Reputation: 1
Remembering to add the escape character \ can sometimes be confusing not just for spaces but for other non ascii characters. The easiest thing to do is to type the first few characters then press tab this will fill in the rest of the file or directory name with all the appropriate escapes in place. If it does not just add another couple of chars or press tab twice quickly to see what the options are.
You can the copy the fully escaped string from the terminal if you want to use it in a script for instance.
Upvotes: 0
Reputation: 157947
You need to quote the directory name:
cd 'Magical Island'
or escape the space character:
cd Magic\ Island
Upvotes: 5
Reputation: 2028
For directory paths with multiple spaces
cd Names\that\ contain\ a\ bunch\ of\ spaces
Upvotes: 0
Reputation: 11
Remembering to add the escape character \ can sometimes be confusing not just for spaces but for other non ascii characters. The easiest thing to do is to type the first few characters then press tab this will fill in the rest of the file or directory name with all the appropriate escapes in place. If it does not just add another couple of chars or press tab twice quickly to see what the options are.
You can the copy the fully escaped string from the terminal if you want to use it in a script for instance.
Upvotes: 1
Reputation: 10055
cd "Magical Island"
You always need to wrap in double quotes other wise it sees Magical and Island as separate arguments
Upvotes: 1