Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - 5 cool terminal pagers in Fedora

#1
5 cool terminal pagers in Fedora

<div style="margin: 5px 5% 10px 5%;"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2019/12/5-cool-terminal-pagers-in-fedora.png" width="761" height="530" title="" alt="" /></div><div><p>Large files like logs or source code can run into the thousands of lines. That makes navigating them difficult, particularly from the terminal. Additionally, most terminal emulators have a scrollback buffer of only a few hundred lines. That can make it impossible to browse large files in the terminal using utilities which print to standard output like <em>cat</em>, <em>head</em> and <em>tail</em>. In the early days of computing, programmers solved these problems by developing utilities for displaying text in the form of virtual “pages” — utilities imaginatively described as <em>pagers</em>.</p>
<p>Pagers offer a number of features which make text file navigation much simpler, including scrolling, search functions, and the ability to feature as part of a <a href="https://fedoramagazine.org/command-line-quick-tips-using-pipes-to-connect-tools/">pipeline</a> of commands. In contrast to most text editors, some terminal pagers do not require loading the entire file for viewing, which makes them faster, especially for very large files.</p>
<p>In the modern era of Linux computing, terminal emulators are more sophisticated than ever. They offer support for a kaleidoscope of colors, terminal resizing, as well as a host of other features to make parsing text on screen easier and more efficient. Terminal pagers have undergone a similar evolution, from extremely simple UNIX utilities like <em>pg</em> and <em>more</em>, to sophisticated programs with a wide range of features, covering any number of use cases. With this in mind, we’ve put together a list of some of the most popular terminal paging utilities — more or less.</p>
<p> <span id="more-29502"></span> </p>
<h3>More</h3>
<p><em>more</em> is one of the earliest pagers, initially featured in version 3.0 BSD. The first implementation of <em>more</em> was written in 1978 by <a href="https://danhalbert.org/more.html">Daniel Halbert</a>. Since then, <em>more</em> has become a ubiquitous feature of many operating systems, including Windows, OS/2, MacOS and most linux distributions.</p>
<p><em>more</em> is a very lightweight utility. The version featured in util-linux runs to just under 2100 lines of C. However, this small footprint comes at a price. Most versions of <em>more</em> feature relatively limited functionality, with no support for backwards scroll or search. Commands are similarly stripped back: press enter to scroll one line, or space to scroll one page. Some other useful commands include:</p>
<ul>
<li>Press v while reading to open the current file in your default terminal editor. </li>
<li>‘/<em>pattern</em>‘ let’s you search for the next occurrence of <em>pattern</em>.</li>
<li>:n and :p will open the next and previous files respectively when more is called with more than one file as arguments</li>
</ul>
<h3>Less</h3>
<p><em>less</em> was initially conceived as a successor to <em>more</em>, addressing some of its limitations. Building on the functionality of <em>more</em>, <em>less</em> adds a number of useful features including backwards scroll, backwards search. It is also more amenable to window resizing.</p>
<p>Navigation in <em>less</em> is similar to <em>more</em>, though <em>less</em> borrows a few useful commands from the <em>vi</em> editor as well. Users can navigate the document using the familiar home row navigational keys. A glance at the man page for <em>less</em> reveals a fairly rich repertoire of available commands. Some particularly useful examples include:</p>
<ul>
<li>?<em>pattern</em> lets you search backwards in the file for <em>pattern</em></li>
<li>&amp;<em>pattern</em> shows only lines which feature <em>pattern</em>. This is particularly useful for those who find themselves issuing <strong>$ grep pattern | less</strong> regularly. </li>
<li>Calling less with the -s (–sqeueeze-blank-lines) flag allows you to view text files with large gaps. Multiple newline characters are reduced to single breaks.</li>
<li>s <em>filename</em>, called from within the program, saves input to <em>filename</em> (if input is a pipe). </li>
<li>Alternatively, calling less with the -o <em>filename</em> flag will save the input of less to <em>filename.</em></li>
</ul>
<p>With this enhanced functionality comes a little extra weight. The version of <em>less</em> that ships with Fedora at the time of writing clocks in at around 25000 lines of source code. Granted, for all but the most storage constrained systems, this is a non-issue. Besides, <em>less</em> is more than <em>more</em>.</p>
<h3>Most</h3>
<p>While <em>less</em> aims to expand on the existing capabilities of <em>more</em>, <em>most</em> takes a different approach. Rather than expanding on the traditional single file view, <em>most</em> gives users the ability to split their view into “windows.” Each window contains different files in different viewing modes.<br />Significantly, <em>most</em> takes into account the width of its input text. The default viewing mode doesn’t wrap text (-S in less), a feature particularly useful when dealing with “wide” files. While these design decisions might represent a significant departure from tradition for some users, the end result is very powerful.</p>
<p>In addition to the navigation commands offered by <em>more</em>, <em>most</em> uses intuitive mnemonics for file navigation. For example, <em><strong>t</strong></em> moves to the <strong>t</strong>op of a file, and <em><strong>b</strong></em> moves to the bottom. As a result, users unfamiliar with <em>vi</em> and its descendants will find most to be refreshingly simple.</p>
<p>The distinguishing feature of <em>most</em> is its ability to split windows and contexts quickly and easily. For example, one could open two distinct text files using the following:</p>
<pre class="wp-block-preformatted">$ most textFile1.txt textFile2.txt</pre>
<p>In order to split the screen horizontally, use the key combos <strong>Ctrl+x, 2</strong> or <strong>Ctrl+w, 2</strong>. The command <em>:n</em> will open the next file argument in a given window, offering a split screen view of two files:</p>
<figure class="wp-block-image"><img src="https://www.sickgaming.net/blog/wp-content/uploads/2019/12/5-cool-terminal-pagers-in-fedora.png" alt="" class="wp-image-29697" /></figure>
<p>If you turn wrap off in one window, it does not affect the behavior of other windows. The \ character indicates a wrap or fold, while the $ character indicates that the file extends past the limitations of the current window.</p>
<h3>pspg</h3>
<p>Those who work with SQL databases often need to be able to examine the contents of our databases at a glance. The command line interfaces for many popular open source DBMS’s, such as MySQL and PostGreSQL, use the system default pager to view outputs that don’t fit on a single screen. Utilities like <em>more</em> and <em>less</em> are designed around the idea of presenting text files, but for more structured data, leave something to be desired. Naive text paginating programs have no concept of broad, tabular data, which can be frustrating when dealing with large queries.</p>
<p><a href="https://github.com/okbob/pspg">pspg</a> attempts to address this by offering users the ability to freeze columns while viewing, sort data <em>in situ</em>, and colourize output. While <em>pspg</em> was intended initially to serve as a pager replacement for <em>psql</em> specifically, the program also supports the viewing of CSV data, and is a suitable drop-in replacement for <em>mysql</em> and <em>pgcli</em>. </p>
<h3>Vim</h3>
<p>In a modern, technicolor terminal, the idea of endless pages of drab grey on black text can feel like something of an anachronism. The syntax highlighting options offered by powerful text editors like <em>vim</em> can be useful for browsing source code. Furthermore, the search functions offered by <em>vim</em> vastly outclass the competition. With this in mind, <em>vim</em> ships with a shell script <em>less.sh</em> that lets <em>vim</em> serve as a replacement for conventional pagers.</p>
<p>To set <em>vim</em> as <a href="https://zameermanji.com/blog/2012/12/30/using-vim-as-manpager/">the default pager</a> for man pages, add the following to your shell’s config (such as <em>~/.bashrc</em> if using the default bash shell):</p>
<pre class="wp-block-preformatted">export MANPAGER="/bin/sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu noma' -\""</pre>
<p>Alternatively, to set <em>vim</em> as the default pager system-wide, locate the <em>less.sh</em> script. (You can find it at <em>/usr/share/vim/vim81/macros/</em> on current Fedora systems.) Export this location as the variable <em>PAGER</em> to set it as default, or under an alias to invoke it explicitly.</p>
<hr class="wp-block-separator" />
<p><em>Photo by <a href="https://unsplash.com/@zyljosa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Cathy Mü</a> on <a href="https://unsplash.com/s/photos/pages?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>.</em></p>
</div>


https://www.sickgaming.net/blog/2019/12/...in-fedora/
Reply



Forum Jump:


Users browsing this thread:
3 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016