user3450695
user3450695

Reputation: 2551

How can I go to a directory whose file name has spaces between them in the Linux terminal?

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

Answers (5)

britesc
britesc

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

hek2mgl
hek2mgl

Reputation: 157947

You need to quote the directory name:

cd 'Magical Island'

or escape the space character:

cd Magic\ Island

Upvotes: 5

Laser Hawk
Laser Hawk

Reputation: 2028

For directory paths with multiple spaces

cd Names\that\ contain\ a\ bunch\ of\ spaces

Upvotes: 0

dfreefggg
dfreefggg

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

CathalMF
CathalMF

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

Related Questions