:
find . -name \*log\* | xargs -I{} sh -c "grep --color=always -iH pattern {} | tail -n1"
First appearance of the search pattern in each log file in the current directory:
find . -name \*log\* | xargs -I{} sh -c "grep --color=always -iH pattern {} | head -n1"
replace 1in -n1with the number of occurrences you want
Alternatively you can use find -execinsteadxargs
find . -name \*log\* -exec sh -c "grep --color=always -iH pattern {} | tail -n1" \;
You can use -mtimewith findto limit the search for log files to say 5 days
find . -mtime -5 -name \*log\* | xargs -I{} sh -c "grep --color=always -iH pattern {} | tail -n1"
source
share