|Lesson 4|| Viewing compressed files|
zcat to view compressed files.
Viewing compressed files (zcat)
Sometimes you’d like to see what’s inside a compressed file. To do so, you can uncompress the file, look inside (using
View the SlideShow below to explore how you can use
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
grep. For example, to search for the name
Daniel in a compressed file
big_list.Z, you would enter:
% zcat big_list | grep Daniel
Note that I omitted the
.Z extension in the above command. Like the
zcat doesn’t care whether you specify the
.Z or not.
Some UNIX systems provide the
zmore command, which is similar to
more but works with compressed files. Instead of entering
zcat file | more, you can simply enter
What is the function of the zmore command in Unix?
The zmore command in Unix is a command-line utility that allows you to view the contents of compressed text files on the terminal. It is a simple way to view compressed files without having to first decompress them to an uncompressed file.
The zmore command works by using the more command to page through the contents of the compressed file, while also using the zcat command to decompress the file on-the-fly. This allows you to view the contents of the compressed file as if it were an uncompressed text file.
Here is the basic syntax for the zmore command:
zmore [OPTIONS] [COMPRESSED_FILE]
Here are some common options for the zmore command:
- -h or --help: display help information
- -q or --quiet: suppress informational messages
- -p or --prompt: change the prompt for the more command
- -c or --clear-screen: clear the screen before displaying the file
Here are some examples of how to use the zmore command:
- To view the contents of a compressed file:
- To view the contents of a compressed file without informational messages:
zmore -q file.gz
- To view the contents of a compressed file with a custom prompt:
zmore -p "Enter to continue..." file.gz
- To clear the screen before displaying the file:
The zmore command is often used in combination with other Unix commands to process or manipulate compressed text files. For example, piping the output of zmore to the grep command can be used to search for specific patterns within compressed files, while piping the output of zmore to the sed command can be used to perform text substitutions within compressed files.
zmore -c file.gz
Disk Usage file Compression - Quiz
In the next lesson, you will learn about file archives.