You can’t do it with find without rewriting find.
You requested no pipes, but it’s not possible without.
find . -print0 |
perl -0ne 'print if /some perl regexp/s' |
xargs -r0 …
Where … is what you do with the files if just writing them to disk is insufficient.
Instead of perl
, with GNU grep
, you can also use grep -zP
(or grep --null -P
slightly more portable for grep
s of some BSDs that are based on the API of an older version of GNU grep
).
A closer equivalent to a hypothetical find . -regextype perl -regex 'some perl regexp' -exec cmd {} +
, with shells with support for ksh-style process substitution would be:
xargs -r0a <(
find . -print0 |
perl -0ne 'print if /some perl regexp/s') cmd
Which like -exec cmd {} +
preserves cmd
's stdin. Note that <(...)
still uses pipes.
Note that by default, perl
works byte-wise while find
/grep
tend to work character-wise. The -C
or -Mopen=locale
options can help decode bytes to characters before doing the matching.
Note that -print0
, -r
, -0
, -a
, -z
, -P
, -regex
, -regex-type
are all non-standard GNU extensions, with -print0
/-0
now found in most other implementations. -r
(to not run the command if no file is found) is also common. -regex
(not -regex-type
) as well though the default regex syntax varies with the implementation.
find
sources to includePCRE
, but it seems a bit rude for one person.find
to tools that do support PCREs, so if you explain what the final objective is, we should be able to give you a solution.grep -P
infind . -exec grep -P 're' {} +