I was wondering if this is possible in find command. I am trying to find all the specific files with the following extensions then it will be SED after. Here's my current command script:
find . -regex '.*\.(sh|ini|conf|vhost|xml|php)$' | xargs sed -i -e 's/%%MEFIRST%%/mefirst/g'
unfortunately, I'm not that familiar in regex but something like this is what I need.
The find Command It supports searching by file, folder, name, creation date, modification date, owner and permissions.
Click My PC on the left-pane in File Explorer, or Computer in Windows Explorer. Enter the command kind:=picture into the search box to search all partitions on your hard drive for images saved in JPEG, PNG, GIF and BMP formats.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With