zcommands: Read gzip Compressed Text Files On a Fly

byVivek GiteonAugust 31, 2007

Linux and Unix like operating systems comes with z* commands. These commands allow you to read gzip compressed text files using zless, zcat, zmore and friends commands. The gzip command reduces the size of the files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. z* commands has some cool usage too; such as display the current time in different zonename.

The old way...

Let us say you have a file called data.txt.gz. To display file you need to execute the following command:gzip -d data.txt.gz cat data.txt less data.txt

The new way...

Just use the zless or zmore command to display the contents of a file called data.txt.gz:zless data.txt.gz zmore data.txt.gz

zcat command

Concatenate compressed files and print on the screen without using the cat command. The syntax is:zcat file.gz

zless / zmore commands

zmore and zless is a filter which allows examination of compressed or plain text files one screenplay at a time on a screen. zmore works on files compressed with compress, pack or gzip, and also on uncompressed files. If a file does not exist, zmore looks for a file of the same name with the addition of a .gz, .z or .Z suffix.zmore file.gz zless file.gz

znew command

Znew recompresses files from .Z (compress) format to .gz (gzip) format. If you want to recompress a file already in gzip format, rename the file to force a .Z extension then apply znew.znew file.Z

zdump command

zdump command prints the current time in each zonename named on the command line. Let us say your current time zone is IST (Indian standard time) and like to see time current time for Los Angeles (USA - PDT), enter:date Output:

Fri Aug 31 20:51:39 IST 2007

Now display Los Angeles current time :zdump /usr/share/zoneinfo/America/Los_Angeles Output:

/usr/share/zoneinfo/America/Los_Angeles Fri Aug 31 08:20:31 2007 PDT

zipgrep command

Search files in a ZIP archive for lines matching a pattern:zipgrep *.cpp basesys.zip

Open gzip text files using vim text editor

Just type the following command to open and edit the archived file called file-name-here.txt.gz:$ vim file-name-here.txt.gz If the above example, failed edit your local vim config file (see how to configure vim) to set vim for reading and writing compressed files: