I see in the comments that you found out how to escape it with GNU basic regexes via the nonstandard flag find -regex RE
, but you can also specify a type of regex that supports it without any escapes, making it a bit more legible:
In GNU findutils (Linux), use -regextype posix-extended
:
find . -regextype posix-extended -regex '.*\.(sh|ini|conf|vhost|xml|php)$' | …
In BSD find (FreeBSD find or Mac OS X find), use -E
:
find . -E -regex '.*\.(sh|ini|conf|vhost|xml|php)$' | …
The POSIX spec for find does not support regular expressions at all, but it does support wildcard globbing and -or
, so you could be fully portable with this verbose monster:
find . -name '*.sh' -or -name '*.ini' -or -name '*.conf' \
-or -name '*.vhost' -or -name '*.xml' -or -name '*.php' | …
Be sure those globs are quoted, otherwise the shell will expand them prematurely and you'll get syntax errors (since e.g. find -name a.sh b.sh …
doesn't insert a -or -name
between the two matched files and it won't expand to files in subdirectories).
man find
that your version of find has the-regex
option? Not all do. Are you saying it doesn't work. Looks OK to me, but I my systems doesn't havefind . -regex
, so I can't say for sure. Good luck.find . -regex ".*\.\(sh\|ini\|conf\|vhost\|xml\|php\)" -print | xargs sed -i -e 's/%%MEFIRST%%/mefirst/g'
These script will select all the files with the following extensions: sh, ini, conf, vhost, xml, php and will replace the text %%MEFIRST%% to mefirst inside the files selected.