• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / grep inside gzipped files

grep inside gzipped files

Last updated on September 24, 2018 by Sal Ferrarello

I find myself using grep (or on my local machine ag*) to sift through lots of files looking for a string.

Recently, I SSHed into a server and wanted to search though a bunch of log files that had been gzipped (i.e. they ended in .gz).

I didn’t want to unzip all of the files and make a mess on the server. I wanted to search the files without modifying them.

So instead of using grep

grep -i -r 'string to find' ./

I was able to use a combination of find, xargs, and zgrep

find -name \*.gz -print0 | xargs -0 zgrep 'string to find'

and did indeed find instances of “string to find” in the one of the gzipped files.

* Note: I understand there are other command line tools that search even faster than ag but I’ve not yet found ag to be slow enough in any situation that it is worth my time to upgrade.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Solution Tagged With: command line, grep, gzip

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in