0

I have list of compressed files in a directory /var/log/bb e.g. console.log.1.xz, console.log.2.xz etc. I would like to grep a particular string from these files in a single command. Any ideas on how to achieve this

I have been trying like this

sudo xzcat /var/log/bb | grep 'string' 
1
  • In grep 'string' you aren't greping a string, you're grepping a regexp so naming it string is misleading at best. You should either write grep 'regexp' or grep -F 'string', whichever it is you want to do. Commented Jun 1, 2022 at 15:40

2 Answers 2

1

Using find

find /var/log/bb -iname '*.xz' -type f -exec grep 'string' {} + 

Using grep

$ grep 'string' /var/log/bb/*.xz 
Sign up to request clarification or add additional context in comments.

Comments

0

Suggesting:

grep -l 'string' $(find /var/log/bb -type f -name "*.xz") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.