find not recursive when given a pattern on the command line
find -iname '*.xml'
Otherwise, your shell expands *.xml
to XYZ.xml
, and the command that actually gets executed is
find -iname XYZ.xml
The reason it works if there are no XML files in the current directory is that shells generally leave wildcards unexpanded if they don't match anything. In general, any time you want wildcards to be expanded by a program other than the shell (e.g. by find
, tar
, scp
, etc.) you need to quote them so the shell won't try to expand them itself.
You need to quote your argument like this:
find ./ -name '*.xml'
so that it gets passed to find instead of being expanded by the shell, then passed to find as the expanded version.