Change directory with space followed by '('
22,734
Solution 1
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.
Solution 2
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)"/
Related videos on Youtube
Author by
enedene
Updated on September 18, 2022Comments
-
enedene over 1 year
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?
-
enedene almost 12 yearsYes, Tab completes, but I have two directories with the same name till (x86) so it only completes to "Program Files".
-
lgarzo almost 12 years@enedene That's right, although afterwards you can type
\
and take advantage of completion. -
user almost 12 yearsAn 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 toProgram Files (x86)
. -
MadScientist almost 12 yearsAt 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. -
Lars Rohrbach almost 12 yearsHitting TAB multiple times should cycle through the available matches.
cd Prog
TAB TAB.