bzmore Command in Linux



The bzmore command is a robust utility you can use as a filter for viewing bzip2 compressed files, which are saved with a .bz2 extension. Using the bzmore command, you can view the file's content on the screen without uncompressing it.

While the bzip2 command is used to compress files, you can use many other utilities to perform simple tasks such as comparing, searching, and more without the need to uncompress the files.

  • The bzmore command is just like the "more command", but it is used primarily for compressed bz2 files. The bzmore command allows you to examine compressed or plain text files one screenful at a time and pauses on the terminal, with the bottom line printing "'More'" on the screen.
  • When bzmore pauses and displays --More-- at the bottom of the screen. Pressing the Enter key will display one more line of the file, and pressing the Space key will display another screenful of lines.

Note − A screenful basically means the number of lines that fit on your terminal screen.

Table of Contents

Here is a comprehensive guide to the options available with the bzmore command −

How does the bzmore Command Work?

The bzmore command uses the /etc/termcap file to understand the characteristics of your terminal. This file contains information about different types of terminals and their capabilities.

When you type a command in bzmore, it takes effect immediately. You don't need to press Enter for the command to execute. If you start typing a numerical argument (like 10 for 10 lines), you can cancel it by hitting the line kill character (usually Ctrl-U).

If you make a mistake or want to see the --More-- prompt again, you can hit the erase character (usually Backspace or Ctrl-H). While bzmore is displaying output, you can press the quit key (Ctrl-\) to stop the output. This will bring up the --More-- prompt again, allowing you to enter another command. When you use the quit key, some output might be lost because characters waiting in the terminal's output queue are flushed.

  • bzmore sets the terminal to noecho mode, meaning that what you type won't be displayed on the screen. This allows for continuous output without interruptions. The only exceptions to this are the / (search) and ! (shell command) commands, which will show what you type.
  • If the standard output is not a teletype (a type of terminal), bzmore behaves like bzcat, which means it will simply decompress and display the file contents. However, it will print a header before each file to indicate the file name.
  • In addition, on a terminal that can display 24 lines, bzmore sets the default window size to 22 lines. This means that when you press the Space key, it will display 22 lines at a time.

Syntax for the bzmore Command

The following is the general syntax for the bzmore command −

bzmore [filename...

Different Options Available for the bzmore Command

The following are different options you can use with the bzmore command −

Tag Description
i <space> Display i more lines (or another screenful if no argument is given).
^D or d Display 11 more lines (a "scroll"). If i is given, then the scroll size is set to i.
i z Same as typing a space except that i, if present, becomes the new window size.
i s Skip i lines and print a screenful of lines.
i f Skip i screenfuls and print a screenful of lines.
q or Q Quit reading the current file; go on to the next (if any).
= Display the current line number.
i /expr Search for the i-th occurrence of the regular expression expr. If the pattern is not found, bzmore goes on to the next file (if any). Otherwise, a screenful is displayed, starting two lines before the place where the expression was found.
i n Search for the i-th occurrence of the last regular expression entered.
!command : Invoke a shell with command. The character ! in "command" is replaced with the previous shell command. The sequence \! is replaced by !
:q or :Q Quit reading the current file; go on to the next (if any) (same as q or Q).
. (dot) Repeat the previous command.

Examples of bzmore Command in Linux

In this section, we'll look at some examples of the bzmore command using various options −

View the Contents of a File

To get started, we'll first create a file named file1.txt with numbers containing 1 to 50. Next, we'll compress the file using the bzip2 compression algorithm. After the compression, the file is saved as file1.txt.bz2.

To examine the contents of file1.txt .bz2 compressed file, you can simply run the following command −

bzmore file1.txt.bz2
bzmore Command in Linux1

This command prints a screenful of text on the terminal.

Now you can execute more options on the '-More-' statement present in the end of the terminal.

bzmore Command in Linux2

Display 11 More Lines

To display 11 more lines on the terminal, you can use the "-d" option −

d
bzmore Command in Linux3

Display More Lines

To display more lines on the terminal, you can use the i(space) syntax as shown −

4(space)
bzmore Command in Linux4

Display 5 More Lines and Set Scroll to 5

To display 5 more lines and set the scroll to 5, you can use the following syntax −

5z
bzmore Command in Linux5

Skip 2 Lines and print 3 Lines (Previously Saved)

To skip 2 lines and print the lines according to the previously saved 5 lines, you can use the following syntax −

2s
bzmore Command in Linux6

Skip Screenful and Print a Screenful of Lines

To skip whole i screenfuls and print a screenful of lines, you can use the following syntax −

1f
bzmore Command in Linux7

Quit Reading the Current File

To quit reading the current file in your terminal, you can simply use the "-q" flag −

q
bzmore Command in Linux8

Show the Current Line Number

To show the current line number while using bzmore, you can use the following syntax −

=
bzmore Command in Linux9

Repeat the Previously Entered Command

To repeat the previously entered command in bzmore, you can use the . (dot) option −

.
bzmore Command in Linux10

Conclusion

The bzmore command is a versatile utility for viewing bzip2 compressed files directly on your terminal. By allowing you to view one screenful of text at a time and providing a range of interactive options, bzmore enhances your ability to navigate and examine compressed content efficiently.

For practical usage, you can employ options to display additional lines, set custom scroll sizes, or skip lines and screenfuls as needed.

By using the bzmore command, you can efficiently manage and inspect compressed files, making it a valuable tool for handling .bz2 files in a Linux environment.

Advertisements