Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a file structure something like this:

/apps/base/logs1
and 
/apps/base/logs2

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

share|improve this question
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 Jan 19 '13 at 0:08
    
@Ken yes it does print the file names when I execute just the find . -name "*.log" command. –  Ayusman Jan 19 '13 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 '13 at 2:52

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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