0

It seems I can ignore a certain filename pattern (*.dll) on find search by doing

find ! -name '*.dll'

And ignore multiple patterns by doing

$ find . ! -name '*.h' ! -name '*.cpp' ! -name '*.dll'

Is there a short form of this?

I tried (unsuccessfully) the following

$ find . ! -name '*.h *.cpp *.dll'
3
  • Try find . ! -name '*.h','*.cpp','*.dll' and lemme know if it works. I don't ever use the find command so I'm not 100% sure if that will work or not.
    – Layne B
    Feb 12, 2021 at 2:41
  • It doesn't work
    – KcFnMi
    Feb 12, 2021 at 5:01
  • why dont you create a alias of this command find . ! -name '*.h' ! -name '*.cpp' ! -name '*.dll alias mycommand="find . ! -name '.h' ! -name '.cpp' ! -name '*.dll",if you want to persist between shell session add this to your .bashrc, so next time you want to run this just type mycommand so sleek Feb 12, 2021 at 9:36

1 Answer 1

3

If your version of find has a -regex primary, you can use that. Unfortunately, it's nonstandard, and you need extended regex syntax which is even less standard. With GNU find, you use -regextype to set the regular expression syntax (and it goes after the directory to search), so it'd be something like this:

find . -regextype egrep '!' -regex '.*[.](h|cpp|dll)'

With BSD (/macOS) find, you'd use the -E option before the directory to search, so it looks like this:

find -E . '!' -regex '.*[.](h|cpp|dll)'

Note that this is a regular expression, not a glob (wildcard) pattern, so you have to use .* to match any string, and escape or bracket the . so it won't be treated as "match any single character". Also, the regex pattern is matched against the entire path, not just the filename (doesn't matter here, but it would would other patterns).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .