Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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)?

share|improve this question
    
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

2 Answers 2

up vote 6 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.

share|improve this answer
1  
Getting findutils from MacPorts did the trick. –  hekevintran Mar 10 '10 at 9:02
    
Findutils is also available through Homebrew. The command after installing is gfind –  Eric Hu Jun 19 '12 at 23:49

The following work with BSD find on OS X.

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

find . -type f | grep -e ".*\.\(py\|html\)$"
share|improve this answer
    
Found it useful. Thanks! –  Senthil Kumaran Jul 25 '12 at 21:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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