Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extended POSIX utilities using command find on Mac OS X?

I try to do this command on my Mac OS X 10.9 Terminal:

find / -type f -regextype posix-extended -regex "(.*A.*a.*.*)|(.*a.*A.*.*)" -exec tail -n 3 '{}' \;

But the Bash v 3.2 response is:

find: -regextype: unknown primary or operator

I have made a deeply search on Terminal manpages:

man find

man regex

etc...

But I find nothing. Does the Mac OS X Bash v3.2 should to be updated? It seems that the option "-regextype" is not included in the "find".

How can I fix it?

p.s. The command works perfectly on Ubuntu Linux 14.

like image 288
shogitai Avatar asked Aug 02 '14 10:08

shogitai


1 Answers

The simplest answer to your question is that on OS X you need to use the -E option instead of -regextype posix-extended

ie:

find / -type f -regextype posix-extended -regex "(.*A.a..*)|(.*a.A..*)" -exec tail -n 3 '{}' \;

becomes:

find -E / -type f -regex "(.*A.a..*)|(.*a.A..*)" -exec tail -n 3 '{}' \;

and aside from the -exec tail command that complains, the above works on my 10.10 installation.

This is actually covered by the first entry of the man page:

 The options are as follows:

 -E      Interpret regular expressions followed by -regex and -iregex primaries as extended (modern) regular expressions rather than basic
         regular expressions (BRE's).  The re_format(7) manual page fully describes both formats.
like image 146
Chris Conover Avatar answered Sep 30 '22 14:09

Chris Conover