0

Given a list of files, I want to find all the ones ending with either .pem or .cer. This command works to find the PEMs.

find . -d 1 -regex ".*\.pem"

But this command finds nothing:

find . -d 1 -regex ".*\.(pem|cer)"

This syntax works in the BBedit pattern playground. Is there some way to use regex groups with find?

Elliott B
  • 1,103
  • 4
  • 13
  • 35
  • 3
    Possible duplicate of [Use multiple conditions in find regex in shell](https://superuser.com/questions/1488718/use-multiple-conditions-in-find-regex-in-shell) – Kamil Maciorowski Nov 13 '19 at 21:36

2 Answers2

1

I wouldn't even use regexps for this, instead i would use:

find . -name "*.pem" -o -name '*.cer'

It might even be faster (although we are talking about fraction of seconds here) because parsing regexps is more expensive in cputime.

EDIT:

Now that I see Hannu's comment, I notice (based on the command that you originally tried) that maybe you don't want to check subdirs. If this is the case then it becomes:

find . -maxdepth 1 -name "*.pem" -o -name '*.cer'

Garo
  • 121
  • 5
0

This command finds nothing:

find . -d 1 -regex ".*\.(pem|cer)"

You need to use ' instead of " and escape ( and ) as follows:

find . -d 1 -regex '.*\.\(pem|cer\)'
DavidPostill
  • 153,128
  • 77
  • 353
  • 394