OSXFAQ Mac OS X UNIX Tip-of-the-Day

Week 106 - New in Tiger (2 January 2006)
by
Adrian Mayo - Editor, OSXFAQ
Monday - Zcat in now Gzcat
In versions of Mac OS X prior to 10.4 (Tiger), the zcat command was, like other z-commands, part of the GNU zip tool set. It could be used to directly display gzip compressed files.
But historically, zcat has existed to directly display files compressed by the Unix compress command (the extension used for this sort of file is .Z). The command was often overwritten by the GNU version.
In Tiger, the original zcat is preserved, and the GNU version is named gzcat. Therefore, always use gzcat unless the target file really was created by compress.
$ zcat /var/log/system.log.0.gz
zcat: /var/log/system.log.0.gz.Z: No such file or directory
$ zcat /var/log/system.log.0
zcat: /var/log/system.log.0.Z: No such file or directory
$ gzcat /var/log/system.log.0.gz
...
Jan 1 18:11:36 Sauron kernel[0]: AFP_VFS afpfs_mount: ...
Jan 1 18:11:49 Sauron kernel[0]: AFP_VFS afpfs_unmount: ...
...
Note that in pre Tiger systems gzcat was installed as zcat and gzcat. Use gzcat in scripts for portability.
Here's a reminder of the many z-variant commands available:
zcat zdiff zfgrep zgrep zmore zprint
zcmp zegrep zforce zless znew
Note that znew can be used to recompress .Z files to .gz files. Also included the very useful zless, lacking in earlier versions of Mac OS X.
Remember too that bzip2 compressed files have a similar set of utilities.
bzcat bzdiff bzfgrep bzip2 bzless
bzcmp bzegrep bzgrep bzip2recover bzmore
Visit the Site of the Book of the Unix Tips:
Project 22 covers the gzcat command.
Project 27 shows how to compress files.
Discuss this trick in the
Learning Center forum
|