I have a bunch of logs and I don't want to look in each of it individually but instead I'd like to run cat cluster-2010*.log | grep error but the problem is that even though it's returning me what I want I don't have a clue which .log file is containing the error that the previous command was displaying.

How can I solve this?

  • 6
    You remove the unneeded cat ? Sep 6, 2016 at 14:53

3 Answers 3


grep will tell you itself if you give it the filenames instead of feeding it their content:

grep error cluster-2010*.log

That is a Useless Use of Cat. Simply do:

grep error cluster-2010*.log

You will get output similar to this:

bil@daemon:foo %>grep error cluster-2010*.log 

If you don't want a bunch of outputs, for example if I get auth.log for failure and it spits out a few hundred lines, you can use:

grep -l error cluster-2010*.log

which will print nothing if the result is false (doesn't contain the value) or the filename if it does.

If you want to figure out what line number the word you are looking for is on, you can use:

grep -n error cluster-2010*.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .