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
find . -name "*.log" -execdir ls -l {} \;
(N.B. you should use-execdir
not-exec
for security reasons. Seeman find
.)