Linux provides tools to simplify various tasks, such as viewing the contents of compressed files without extracting them. One such tool is zmore, which we will explore in this tutorial through practical examples.
Note: All examples have been tested on an Ubuntu 24.04 LTS system.
Understanding the Linux zmore Command
The zmore command serves as a file perusal filter for viewing compressed text files one screen at a time. Here’s its syntax:
zmore [name ... ]
From the manual:
Zmore is a filter for examining compressed or plain text files one screenful at a time on a terminal. It works on files compressed with compress, pack, gzip, and also on uncompressed files. If a file does not exist, zmore searches for a file with a .gz, .z, or .Z suffix. Normally, zmore pauses after each screenful, printing --More-- at the bottom. The user can press Enter for another line or space for another screenful, among other options.
Q1. How to Use zmore?
If you want to view the contents of a compressed file, like test.html.gz, on your screen, use the following command:
zmore test.html.gz
This command displays the first page of the file:
Press Enter to scroll one line at a time or q to quit.
Q2. How to Scroll Multiple Lines at a Time with zmore?
Instead of pressing Enter multiple times, press the spacebar to scroll one screen at a time. To scroll multiple lines, press ‘i’ followed by the number of lines you want to scroll.
i <space> - Redisplay the next 'i' lines, or a screenful if no number is given.
Or, press Ctrl+D to display 11 more lines by default:
^D - Display 11 more lines. If 'i' is set, the scroll size becomes 'i'.
Q3. How to Skip Lines or Screens in zmore?
To skip lines or screens, use the following commands:
is - Skip 'i' lines and display a screen of lines.
if - Skip 'i' screens and display a screen of lines.
Q4. How to Display the Current Line Number in zmore?
Press ‘=’ at any time to display the current line number. For example, pressing ‘=’ might display the number 35, as shown:
Q5. How Does zmore Determine Terminal Characteristics?
zmore uses the /etc/termcap file to ascertain terminal characteristics and the default window size (22 lines for 24-line displays). To change window size, you can type ‘iz’:
iz - Similar to typing a space but sets 'i' (if present) as the new window size.
Conclusion
The zmore command is particularly useful when working with compressed files. Its learning curve is gentle, and we’ve covered several key features. For more details, refer to the man page.
Frequently Asked Questions (FAQ)
- Can zmore handle uncompressed files?
Yes, zmore can handle both compressed and uncompressed text files. - Which compression formats does zmore support?
It supports compress, pack, and gzip formats. - How do I quit zmore?
Press ‘q’ to quit at any time during viewing. - Is zmore specific to Ubuntu?
No, zmore can be found on various Linux distributions, though it may require installation on some. - How can I change the pager program used by zmore?
Set the environment variable PAGER to your preferred program, like ‘less’.