Lesson 4 | Viewing compressed files |
Objective | Use zcat to view compressed files. |
cat
or more
, for example), and then compress the file again. But this is inconvenient, especially if there are several compressed files you’d like to check. An easier way is to use the zcat
command, like this:
% zcat file
zcat
reads the given file without restoring the original version. In other words, zcat
decodes the file and displays it on your screen. Typically, you pipe the output of zcat
to another program, such as more
or grep
. For example, to search for the name Daniel
in a compressed file named big_list.Z
, you would enter:
% zcat big_list | grep DanielNote that I omitted the
.Z
extension in the above command. Like the uncompress
command, zcat
doesn’t care whether you specify the .Z
or not.
View the following series of images below to explore how you can use zcat .
danielg % pwd /export/home/danielg/project/qa danielg % ls index.html test_plan.html.Z danielg %
danielg % zcat test_plan.html | more <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="author" content="Peter Mock"> <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT: I) [eCyberCom]"> <title>eCyberCom 1.0 Test Plan</title> </head> <body>--More--
danielg % zcat index.html index.html.Z: No such file or directory danielg %
zmore
command, which is similar to more
but works with compressed files. Instead of entering zcat file | more
, you can simply enter zmore
file
.
zmore [OPTIONS] [COMPRESSED_FILE]
zmore file.gz
zmore -q file.gz
zmore -p "Enter to continue..." file.gz
zmore -c file.gz