Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello I want to output ERROR messages from logfiles from the current date.

First I search for the logs of today with specific prefix:

find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" -daystart -mtime -1

It gives me that output:


In these files I want to search for the string "ERROR":

grep -rl "ERROR" /home/USER/logfilesError/

This gives me all the Logfiles containing "ERROR" not only from today.

Output(only some of the output):



How can I combine those in a script?

The Syntax from a line in the logfiles are:

2013-11-24 06:30:30,549 [main] ERROR *(+Errormessage)*
share|improve this question

Try this:

find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" \
    -daystart -mtime -1 -exec grep -Hl "ERROR" "{}" +

From man find:

-exec command {} +
              This  variant  of the -exec action runs the specified command on
              the selected files, but the command line is built  by  appending
              each  selected file name at the end; the total number of invoca‐
              tions of the command will  be  much  less  than  the  number  of
              matched  files.   The command line is built in much the same way
              that xargs builds its command lines.  Only one instance of  `{}'
              is  allowed  within the command.  The command is executed in the
              starting directory.
share|improve this answer
Or if your grep is not the GNU grep: -exec grep -l ERROR /dev/null {} + – Stéphane Chazelas Jun 6 '14 at 8:29

Your Answer


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.