I have a file structure something like this:


Both logs1 and logs2 folders have .log files with some other files as well.

I am trying to do this From /apps folder I want to be able to find all files (folders and sub-folders) that have the string "ERROR".

This command

 find . -name "*.log" -exec grep -H "ERROR" '{}' \; -print

Works fine and shows me all .log files directly in the folder when I am in the folder /apps/base/logs1 or /apps/base/logs2.

But when I switch to the folder /apps, this command does not yield any results.

Is there anything that I am missing or need to change? I have tried several other options but I can not get it to work.

Any help will be appreciated. Thanks

  • 2
    If you run the find command without the -exec, just "find -name '*.log'", does it print out the files you expect to search?
    – Ken Kinder
    Jan 19, 2013 at 0:08
  • @Ken yes it does print the file names when I execute just the find . -name "*.log" command.
    – Ayusman
    Jan 19, 2013 at 0:23
  • What about trying a different command for the sake of troubleshooting? e.g. find . -name "*.log" -execdir ls -l {} \; (N.B. you should use -execdir not -exec for security reasons. See man find.)
    – Sparhawk
    Jan 19, 2013 at 2:52

1 Answer 1


ok, got the answer. Since I was on an enterprise environment, there were many symbolic links created. I had to explicitly ask find command to also follow the symbolic links. So the command now looks like this:

find -L /apps -name "*.log" -exec grep -H "ERROR" '{}' \; -print

The problem was directories like logs1 and logs2 were symbolic links, and hence were not followed by the find command. The -L option forces the command to look in the sym links as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .