Managing Disk Space   «Prev  Next»
Lesson 4 Viewing compressed files
ObjectiveUse 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 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 Daniel
Note 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 SlideShow below to explore how you can use zcat.
1)
2)
3)
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 zmore file.

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:
  1. -h or --help: display help information
  2. -q or --quiet: suppress informational messages
  3. -p or --prompt: change the prompt for the more command
  4. -c or --clear-screen: clear the screen before displaying the file
Here are some examples of how to use the zmore command:
  1. To view the contents of a compressed file:
    zmore file.gz
    

  2. To view the contents of a compressed file without informational messages:
    zmore -q file.gz
    

  3. To view the contents of a compressed file with a custom prompt:
    zmore -p "Enter to continue..." file.gz
    

  4. To clear the screen before displaying the file:
    zmore -c file.gz
    

  5. 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.

Disk Usage file Compression - Quiz

Click the Quiz link below to test your knowledge of disk usage and file compression.
Disk Usage file Compression - Quiz

In the next lesson, you will learn about file archives.