Wednesday, August 6, 2014

find command two multiple file extensions with regular expression

# find . -type f -name '*.module' -o -name '*.js' | xargs -I {} grep -riH 'find_string' {}
# find -E . -type f -regex '.*\.(module|js)' | xargs -I {} grep -riH 'find_string' {}

Note: That -E flag is a BSDism (OS X having a largely BSD-ish userland). On GNU find, you instead say -regextype posix-extended, as an expression rather than a flag (according to Dennis Williamson's comment, which is doubtless correct).

No comments: