Ubuntu – How to delete all files that contains “ (2)” wildcards dont work

rmwildcards

I would like to delete all files that contains " (2)" –whitout the quotes– in the file names. I tried first with ls to test

ls *(2)*

and list all the files in the folder

ls "*(2)*" 

don't list any file, how I have to format the wildcard to do the right thing?

Thanks

Best Answer

You need to escape (or quote) the parentheses - but not the glob wildcards * e.g.

ls *\(2\)*

or

ls *"(2)"*

or even

ls *'('2')'*

If you want to match the leading space explicitly, you will need to escape or quote that as well e.g.

ls *\ \(2\)*

or

ls *' (2)'*