7

There are two directories I can change to:

Program Files/ Program Files (x86)/ 

I can change to first one by writing:

cd Program\ Files 

But the second for second one:

cd Program\ Files\ (x86) 

I get:

bash: syntax error near unexpected token `(' 

What is the right way to change to second directory?

2 Answers 2

11

You have to escape the parentheses:

cd Program\ Files\ \(x86\) 

Pressing TAB will usually complete the command line for you, and will give hints how to quote the file/directory names.

5
  • Yes, Tab completes, but I have two directories with the same name till (x86) so it only completes to "Program Files". Commented Jun 11, 2012 at 8:46
  • @enedene That's right, although afterwards you can type \ and take advantage of completion. Commented Jun 11, 2012 at 8:51
  • An alternative that may be useful in this case is to use shell globbing. For example, cd P TAB ??x86? TAB will likely (depending on what else you have in the relevant directory) complete out to Program Files (x86). Commented Jun 11, 2012 at 9:08
  • 1
    At some point backslashes become more of a problem than they're worth. If you have more than one or two special characters it's simpler to quote the entire file name; either "Program Files (x86)" or 'Program Files (x86)' will work. Commented Jun 11, 2012 at 12:34
  • Hitting TAB multiple times should cycle through the available matches. cd Prog TAB TAB. Commented Jun 11, 2012 at 14:53
3

Another way to accomplish the same is to quote the path containing whitespace:

cd "Program Files (x86)" 

This also works with tab-completion so you can type:

cd "Program<Space><Tab><Space><Tab> 

Notice the opening double-quote. Then you will get:

cd "Program Files (x86)"/ 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.