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.