up vote 2 down vote favorite
1
share [g+] share [fb]

I have a project directory that contains source code and subdirectories of source code. I want to use the Unix program find to search recursively for the names of files of certain extensions. The versions of find on Linux and Mac OS X behave differently.

# Works in Linux
find . -type f -regex ".*\.\(py\|html\)$"

# Neither of these works in Mac OS X
find . -type f -regex ".*\.\(py\|html\)$"
find . -type f -regex ".*\.(py|html)$"

How do I write this command so that it will run on Mac OS X (and hopefully on Linux too)?

link|improve this question

73% accept rate
It would be helpful if you told us in what way they behave differently. – Nifle Mar 10 '10 at 8:27
The command is supposed to find files. On OS X, the same command finds nothing (zero files). – hekevintran Mar 10 '10 at 8:29
feedback

2 Answers

up vote 5 down vote accepted

Mac OS X uses BSD find and most Linux distributions come with GNU find. I believe you can install GNU findutils onto Mac OS X. I don't have a Mac handy, but I am sure it was available in MacPorts.

Looking at the BSD find man page I could make a wild guess and suggest you try looking at the -E option to enable the modern regular expression library.

link|improve this answer
1  
Getting findutils from MacPorts did the trick. – hekevintran Mar 10 '10 at 9:02
feedback

The following work with BSD find on OS X.

find -E . -type f -regex ".*\.(py|html)$"

find . -type f | grep -e ".*\.\(py\|html\)$"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.