find . -regex '.*\.\([chCH]\|cc\|CC\)'
will find all files with names ending in .c,.C,.h,.H,.cc and .CC and does not find any that end in .hc, .cC, or .Cc. In the regex, the first few characters match through the last period in a name, and the parenthesized alternatives match any of the single characters c, h, C, or H, or either of cc or CC.
Note, find's -regex
and -iregex
switches are analogous to -name
and -iname
, but the regex-type switches allow regular expressions with |
for alternative matches. Like -iname
, -iregex
is case-insensitive.
The (non-functional) form
find . -name '*.[cCHh][cC]?$'
given in a previous answer doesn't list any names on my linux system with GNU find 4.4.2.
Another problem with '*.[cCHh][cC]?$'
as a regex is that it will match names like abc.Cc
and xyz.hc
which are not in the set of .c,.C,.h,.H,.cc and .CC files that you want.