Tell me more ×
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 at 0:08
@Ken yes it does print the file names when I execute just the find . -name "*.log" command. – Ayusman Jan 19 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 at 2:52

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.