Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the five coolest terminal paging machines?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Which are the five coolest terminal pager? I believe many inexperienced people are at a loss about this. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Large files such as logs or source code can be as many as thousands of lines, which makes it very difficult to navigate within files, especially on terminals. In addition, most terminal emulators have rollback buffers of only a few hundred lines. This may make it impossible to browse large files in the terminal using utilities that print to standard output, such as cat, head, and tail. In the early days of the computing age, programmers solved these problems by developing utilities for displaying text in the form of virtual "pages", which were vividly described as the pager pager.

The pager provides a number of features that make text file navigation easier, including scrolling, searching, and as part of the command pipeline. Compared to most text editors, some terminal pager does not need to load the entire file to view, which makes them faster, especially for very large files.

In the era of modern Linux computing, terminal simulators are more complex than ever. They provide support for colorful colors, terminal resizing, and many other features that make it easier and more efficient to distinguish text on the screen. The terminal pager has undergone a similar evolution from extremely simple UNIX utilities such as pg and more to complex programs with a wide range of features covering a variety of usage scenarios. With this in mind, we have compiled a list of some of the most popular terminal paging utilities either "more" or "less".

More

More is one of the earliest paging machines, which originally appeared in the 3.0 BSD version. The first implementation of more was written by Daniel Halbert in 1978. Since then, more has become a common feature of many operating systems, including Windows, OS/2,MacOS, and most Linux distributions.

More is a very lightweight utility. The version available in the util-linux package has less than 2100 lines of C code. However, this small code size comes at a cost. Most versions of more have relatively limited functionality and do not support scrolling or searching backwards. The command is equally concise: press enter to scroll one line, or press Spacebar to scroll one page. Other useful commands include:

Press v while reading to open the current file in the default terminal editor.

/ pattern allows you to search for the next "pattern" that appears.

When more is called with multiple files as parameters,: n and: P will open the next and previous files # less, respectively

Less was initially considered to be the successor to more, addressing some of its limitations. Less builds on the capabilities of more and adds many useful features, including scrolling backwards and searching backwards. It is also more suitable for window resizing.

Navigation in less is similar to more, although less also borrows some useful commands from the vi editor. Users can browse the document using the familiar main line navigation keys home row navigational keys. A glance at the man pages of less shows that there are quite a few commands available. Some particularly useful examples include:

? Patterns allow you to search backwards for "patterns" in files.

& the mode displays only rows with the "mode" feature. This is especially useful for people who find that they often use the $grep mode | less.

Use the-s (or-sqeueeze-blank-lines) flag to call less so that you can view text files with large white space. Multiple newline characters are reduced to a single break line.

The s file name called in the program saves the input to the file name (if the input comes from a pipe).

Alternatively, calling less with the-o filename flag will save the input of less to the filename. With these enhanced functions, there is also a slight increase in volume. At the time of this writing, the version of less that came with Fedora had about 25000 lines of source code. Of course, this is not a problem on all other systems unless it is the system with the greatest storage constraints. Less has more features than more.

Most

Less is designed to extend the existing capabilities of more, while most takes a different approach. Instead of extending on the traditional view of a single file, most enables users to split their view into "windows". Each window contains different files in a different viewing mode.

Importantly, most takes into account the width of its input text. The default view mode is not wrapped (the-S parameter in less), which is especially useful when working with "wide" files. Although for some users, these design decisions may represent a significant departure from tradition, the end result is very powerful.

In addition to the navigation commands provided by more, most uses intuitive mnemonics for file navigation. For example, t moves to the top of the file (Top) and b moves to the bottom (Bottom). In this way, users who are not familiar with vi and its derivatives will find most very easy to use.

What makes most unique is its ability to split windows and contexts quickly and easily. For example, you can open two different text files using the following command:

$most textFile1.txt textFile2.txt

To split the screen horizontally, use the key combinations Ctrl+x, 2 or Ctrl+w, 2. The: n command opens the next file parameter in a given window, providing a split-screen view of the two files:

If you turn off line wrapping in one window, it does not affect the behavior of other windows. The\ character at the end of the line indicates a line break or collapse, while the $character indicates that the file exceeds the limit of the current window.

Pspg

People who use SQL databases usually need to be able to check the contents of the database at a glance. The command-line interfaces of many popular open source DBMS, such as MySQL and PostGreSQL, use the system's default pager to view output that cannot be displayed on a single screen. Utilities such as more and less are designed around the idea of rendering text files, but there are some shortcomings for more structured data. Naive text paging programs do not have the concept of wide tabular data, which can be frustrating when dealing with large queries.

Pspg attempts to solve this problem by providing users with the ability to freeze columns while viewing, sort data in place, and color the output. Although pspg was originally used specifically as a replacement for psql's pager, the program also supports viewing CSV data and is a suitable direct alternative to mysql and pgcli.

Vim

In modern brightly colored terminals, the gray text on endless black pages feels out of date. Syntax highlighting options provided by powerful text editors such as vim are useful for browsing the source code. In addition, vim provides far more search capabilities than its competitors. With this in mind, vim comes with a shell script, less.sh, that enables vim to replace the traditional pager.

To set vim as the default pager for man pages, add the following to the configuration of shell (~ / .bashrc if the default bash shell is used):

Export MANPAGER= "/ bin/sh-c\" col-b | vim-c 'set ft=man ts=8 nomod nolist nonu noma' -\ ""

Or, to set vim as the system-wide default pager, locate the less.sh script. You can find it at / usr/share/vim/vim81/macros/ on the current Fedora system. Export this location as a variable PAGER to set it as the default value, or set it as an alias to explicitly call it

After reading the above, have you mastered which of the five coolest terminal paging devices are? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report