Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to remove all files in a Windows 7 directory with filenames containing brackets; ( and ):

Using MinGW:

rm *(*)*

I get an error:

sh: syntax error near unexpected token '('

I assume this is because the rm command sees a bracket as some sort of special input. What could I do instead?

share|improve this question
up vote 3 down vote accepted

You can "escape" specific metacharacters by prefixing with backslash.

$ touch 'aaa(bbb)ccc'
$ rm *\(*\)*
$ ls
share|improve this answer
rm '*(*)*' gives me rm: cannot lstat *()': No such file or directory. rm *(*)*` works (but also wants to delete directories with this match but that's what the original of the OP wants too, giving an error-line). – Rik Oct 8 '13 at 9:39
Using quotes did not work for me. The escape backslash did though. @Rik - Apologies - I was not specific. The directory I am looking at has no sub-directories. – atomh33ls Oct 8 '13 at 9:45
@RedGrittyBrick The first method only works on the one file named *(*)*, but OP wants to work on all files containing ( and ). Try it yourself with a touch 'a(b)c'. Then rm '*(*)*' does not work on all these files. Also not in bash on Linux! The rm *\(*\)* does work on both Linux and mingw. – Rik Oct 8 '13 at 9:57
@Rik: Thanks, I was aware of that (which is why I mentioned "all metacharacters") - but maybe it is confusing to include that in this answer - I'll remove it. – RedGrittyBrick Oct 8 '13 at 10:19

You can do the following:

find . -type f -name "*(*)*" -delete -maxdepth 1

For testing I would use the -print argument first:

find . -type f -name "*(*)*" -print -maxdepth 1

If you want to do it in all subdirectories you can ommit the -maxdepth 1

If the -delete does not work you can try:

find . -type f -name "*(*)*" -exec rm -rf {} \;

Edit: Included the -type f to only do this on files (and not directories) same as in rm.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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