How to find files using a regular expression

A regular expression can be used to find several different file names when searching using the linux find command.

The example below shows how you can search for files ending with .php or .inc:

find . -regextype posix-extended -regex '.*(php|inc)$' -type f

Any POSIX extended regular expression can be used when searching, for more information on these see: Wikipedia: POSIX Extended Regular Expressions.

Last updated: 05/06/2011