Wednesday·21·November·2012
zutils: zcat and friends on Steroids //at 01:18 //by abe
I recently wrote about tools to handle archives conveniently. If you just have to handle compressed text files, there are some widely known shortcut commands to mimic common commands on files compressed with a specific compression format.
gzip | bzip2 | lzma | xz | |
---|---|---|---|---|
cat | zcat | bzcat | lzcat | xzcat |
cmp | zcmp | bzcmp | lzcmp | xzcmp |
diff | zdiff | bzdiff | lzdiff | xzdiff |
grep | zgrep | bzgrep | lzgrep | xzgrep |
egrep | zegrep | bzegrep | lzegrep | xzegrep |
fgrep | zfgrep | bzfgrep | lzfgrep | xzfgrep |
more | zmore | bzmore | lzmore | xzmore |
less | zless | bzless | lzless | xzless |
In Debian and derivatives, those tools are part of the according
package for that compression utility, i.e. the zcat
command is part of the gzip package and the
xzfgrep
command is part of the xz-utils package.
But despite this matrix is quite easy to remember, the situation has a few drawbacks:
- Those tools can only handle the format they’re written for (which
btw. means that all xz-tools can also handle
lzma
-compressed files aslzma
isxz
’s predecessor) zcat
and the other cat variants can’t even recognize non-compressed files and throw an error instead of just showing their contents.- I always tend to think that
lzcat
and friends are forlzip
-based compression asxzcat
can handlelzma
-compressed files anyway.
This is where the zutils project comes in: zutils provides the
functionality of most of these utilities, too, but with one big
difference: You don’t have to remember, think about or type which
compression method has been used for your data, just use
zcat
, zcmp
, zdiff
,
zgrep
, zegrep
, or zfgrep
and it
works — independently of what compression method has been used
— if any — or if there are different compression types
mixed in the parameters to the same command:
$ zfgrep foobar bla.txt fnord.gz hurz.xz quux.lz bar.lzma
Especially if you use logrotate and let
logrotate
compress old logs, it’s very comfortable that
one command suffices to concatenate all the available logfiles,
including the current uncompressed one:
$ zcat /var/log/syslog* | …
Additionally, zutils’ versions of these tools also support
lzip
-compressed files.
The zutils package is available in Debian starting with
Wheezy and in Ubuntu since Oneiric. When being installed, it replaces
the original z*
utilities from the gzip package
by diverting them away.
The only drawback so far is that there neither a
zless
nor a zmore
utility from the
zutils project, so zless bla.txt fnord.gz hurz.xz quux.lz
bar.lzma
will not work as expected even after
installing zutils as it is still the one from the gzip package and hence it will show you just the first two files in
plain text, but not the remaining ones.
Tagged as: bzip2, Debian, DWIM, gzip, logrotate, lzip, lzma, UUUT, xz, zcat, zcmp, zdiff, zgrep, ztest, zutils
// show without comments // write a comment