Linux zmore Command Tutorial for Beginners (5 Examples)

Sometimes, you may want to view the contents of a compressed file without uncompressing it first. Well, you’ll be glad to know Linux offers a command line utility that lets you do this. In this tutorial, we will discuss the basics of the zmore command using some easy to understand examples.

But before we do that, it’s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.

Linux zmore command

The zmore command in Linux is basically a file perusal filter for crt viewing of compressed text. Following is its syntax:

zmore [ name …  ]

And here’s how the tool’s man page defines it:

Zmore  is  a  filter  which  allows  examination of compressed or plain text files one screenful 
at a time on a soft-copy terminal. 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  normally  pauses  after  each  screenful,  printing --More-- at the bottom of the screen. 
If the user then types a carriage return, one more line is displayed. If the user hits a space,
another screenful is displayed.  Other possibilities are  enumerated later.

Following are some Q&A styled examples that should give you a better idea on how the zmore command works.

Q1. How to use zmore?

Suppose you have a compressed file – test.html.gz in my case – whose contents you want to quickly view one page or line at a time on the terminal screen. Here’s how you can use zmore to do this:

zmore test.html.gz

The aforementioned command produced the following output:

How to use zmore

So you can see the first page of the file was produced in the output. You can press the enter key to scroll and see and the rest of the file one line at a time. To quit press ‘q’.

Q2. How to make zmore scroll file contents multiple lines at a time?

Of course, pressing the enter key multiple times is a way, but it’s definitely not an elegant way out. A better way is to press the spacebar key, which lets you scroll one screen at a time.

However, in case you want to scroll the content multiple lines at a time, just press ‘i’ followed by a number that represents the number of lines to be scrolled.

i<space>
              display i more lines, (or another screenful if no argument is given)

Alternatively, you can also press Ctrl+D to make zmore display 11 more lines.

^D     display 11 more lines (a ``scroll'').  If i is given, then the scroll size is set to i.

Q3. How to make zmore skip lines or screens?

The zmore command offers two options for this:

is - skip i lines and print a screenful of lines

if - skip i screenfuls and print a screenful of lines

Q4. How to make zmore display the current line number?

At any point in time while using zmore, if you want to know the current line number, just press =.

For example, in my case, zmore displayed 35 at the bottom of the screen when I pressed =.

How to make zmore display the current line number

Q5. How zmore determines terminal characteristics?

This is done through the file /etc/termcap. The man page explains it in detail:

Zmore looks in the file /etc/termcap to determine terminal characteristics, and to determine the 
default window size. On a terminal capable of displaying 24 lines, the default window size is 22
lines. To use a pager other than the default more, set  environment variable PAGER to the name of
the desired program, such as less.

To change window size, use the ‘iz’ method. Here’s how it’s explained:

iz  -   same as typing a space except that i, if present, becomes the new window size.

Conclusion

The zmore command is handy for those who deal a lot with compressed files. Learning curve for the tool isn’t steep. We’ve already discussed some useful command line options zmore offers. To learn more, head to the tool’s man page.

Himanshu Arora

About Himanshu Arora

Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu’s work has also been featured in some of world’s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.

Share this page:

linux zmore command tutorial for beginners 5 examples 2
linux zmore command tutorial for beginners 5 examples 3
linux zmore command tutorial for beginners 5 examples 4
linux zmore command tutorial for beginners 5 examples 5

نوشته های مشابه