Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

I'm trying to search multiple zipped files from a single directory. I'm using zgrep to currently search through either one individual file or all based on a wild card character. Here's what I'm currently trying:

Files: 04112012.z, 04122012.z, 04132012.z, etc etc.

  zgrep <search criteria> 0412* | less 

Is there any way that I can search say, only 04112012.z and 04122012.z specifically?


share|improve this question
up vote 2 down vote accepted

Yes, you can specify the particular file names on the command-line, separated by a space, after all the required command switches have been given, but before you pipe the results to less in your case.

As an example, you could use the command below. The -i switch is used so that case is ignored (both upper and lower case results are returned) and -E is invoked so that extended regular expressions can be used:

zgrep -E -i 'gtk|layout' myfile1.gz myfile2.txt.gz myfile3.Z | less

As you know, you can use * instead of a filename to select all files in that folder so that grep searches through those. In addition, you could also use the --include=regex and --exclude=regex switches to target certain groups of file names, as is explained in this article here.

If you have a look at /bin/zgrep (run cat /bin/zgrep), it is actually just a wrapper script, and all the normal grep command switches are valid when it is invoked. As is noted in the zgrep manpage,

Zgrep invokes grep on compressed or gzipped files. All options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep.

For more information, see man zgrep, man grep and the respective Ubuntu manpages online.

share|improve this answer

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.