1

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,347
  • 5
  • 17
  • 44

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
  • 156
1

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
  • 162,382