The find command I am using is recursively listing all the .log files even though the matching pattern is not quoted. As far as I know, if the search pattern is not quoted, it will be expanded by the shell, then find command will work on it,which should give the .log files only in the current directory.

find . -iname *.log


You're probably using one of those shells like bash and most other POSIX shells that don't report an error when globs don't match any file and instead pass the glob verbatim (unexpanded) to the application (and there happens not to be non-hidden files with a .log extension in the current directory).

In those shells, you'll find that

echo *.log



instead of an error like:

zsh: no matches found: *.log`

fish: No matches for wildcard '*.log'. See `help expand`.
echo *.log

echo: No match.

So if there's no .log file in the current directory:

find . -name *.log

Would be the same as

find . -name '*.log'

where a litteral *.log argument is passed to find.

Shells where that has been fix are zsh, csh, tcsh and recent versions of fish (well, in effect it was OK in earlier versions of Unix, but was broken in the Bourne shell in the late 70s and then fixed again in some shells). With bash, you can use shopt -s failglob to get the better behaviour.

Note that if there was one .log file in the current directory (like file.log, it would become:

find . -name file.log

And if there was more than one (like file1.log and file2.log), that would become:

find . -name file1.log file2.log

Which would be an invalid find invocation.


What can be expanded by the shell is the starting-point, in your case . but not the search pattern.
So works as designed.

The command as follows would do the shell expand.

find *log 

This command itself does not make much sense as you also could use

ls -1 *log


As you mentioned in the comments below, your shell is taking care of quoting the search pattern.
And you are right that the search pattern will be expanded by the shell, but that normally will result in an error, which is described in the man page of find in the NON-BUGS section.

  • but *.log should also be expanded by the shell since it is not quoted. – Pankaj Pandey Dec 17 '17 at 10:15
  • I got the verbose output of the above find command I am using .. turns out the shell is explicitly quoting the matching pattern before submitting it to find. Below is the verbose output of the command: pankaj@pankaj-Inspiron-7560:/$ find . -iname .log + find . -iname '.log' – Pankaj Pandey Dec 17 '17 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.