In my man find
page in BSD I see:
-path pattern True if the pathname being examined matches pattern. Special shell pattern matching characters (``['', ``]'', ``*'', and ``?'') may be used as part of pattern. These characters may be matched explicitly by escaping them with a backslash (``\''). Slashes (``/'') are treated as normal characters and do not have to be matched explicitly.
(and -path
is the same as -wholename
and -iwholename
is the same as -path
but case insensitive)
You have to escape these characters because they have special meaning to the shell otherwise. This is the same for other flags like -name
and -iname
.
To make your find
work with arbitrary strings, you need to escape these special characters, for example like this:
escaped=$(sed -e 's/[][?*]/\\&/g' <<< "*aoeu*")
find ./ -iwholename "$escaped"
UPDATE
As you yourself figured out, if you need to replace a lot of patterns per second, it will be more efficient to use bash
to do the replacement instead of spawning a sed
every time, like this:
filename_escaped="${filename//\[/\\[}"
filename_escaped="${filename_escaped//\]/\\]}"
filename_escaped="${filename_escaped//\*/\\*}"
filename_escaped="${filename_escaped//\?/\\?}"