Methods of payment Abuse

What Less means in Linux

26.11.2021, 18:15

The less command allows you to rewind the text not only forward but also backward, search in both directions, go straight to the end or the beginning of the file. The peculiarity of less is that the command does not read the text completely, but loads it in small fragments.

Syntax and options

The less command in the terminal looks like this:

command options file

The most popular options are:

 -a, --search-skip-screen - do not search the text currently displayed on the screen;

-bn, --buffers=n - set the memory buffer size;

-c, --clear-screen - scroll through the text, completely erasing the screen content (line-by-line scrolling will not work);

-Dxcolor, --color=xcolor - set the color of the displayed text;

-E, --QUIT-AT-EOF - exit when the utility reaches the end of the file;

-e, --quit-at-eof - exit when the utility reaches the end of the file a second time;

-F, --quit-if-one-screen - exit if the contents of the file fit on one screen;

-f, --force - open a special file;

-hn, --max-back-scroll=n - set the maximum number of lines to scroll backwards;

-yn, --max-forw-scroll=n - set the maximum number of lines to scroll forward;

-i, --ignore-case - ignore case;

-I, --IGNORE-CASE - ignore case even if the search pattern contains capital letters;

-jn, --jump-target=n - specify in which line the searched information should be output;

-J, --status-column - mark the rows corresponding to the search results;

-n, --line-numbers - do not display line numbers;

-N, --LINE-NUMBERS - display line numbers;

-s, --squeeze-blank-lines - replace many consecutive blank lines with one blank line;

-w, --hilite-unread - highlight the first line of a new text fragment.

While viewing the text, the utility can be controlled by internal commands typed on the computer keyboard. The most frequently used ones are:

 h, H - help;

Space, Ctrl+V, f, Ctrl+F - scroll the text one screen forward;

Enter, Return, Ctrl+N, e, Ctrl+E, j, Ctrl+J - scroll the text for n lines forward, by default n=1;

y, Ctrl+Y, Ctrl+P, k, Ctrl+K - scroll the text for n lines backwards, by default n=1;

Ctrl+→ - scroll the text horizontally to the end of the line;

Ctrl+← - scroll the text horizontally to the beginning of the line;

:d - delete the current file from the list of files;

Ctrl+G, :f - display basic information about the file;

q, Q, :q, :Q, :Q, ZZ - exit.

The list of all options and internal commands can be viewed in the terminal by executing the command

$ man less

How to use LESS

The use of options is not mandatory. You can open a file by executing the following command:

$ less filename.txt

The command line will disappear and the document you specified will open in a terminal window. After that you can read it using Enter and y or other keys to scroll back and forth.

At the bottom of the window you will see a field with a blinking cursor. Here you can type some internal command, for example, to set a search pattern for the utility.

Options are necessary to display text and make working with the utility more convenient. For example, texts often contain multiple empty lines. They "eat" the space on the screen, not bringing any usefulness. That's why you should always add the -s or --squeeze-blank-lines option to the less command - it removes unnecessary blank lines.

$ less -s textfile.txt

Compare what the same text looks like with the -s option (left) and without it (right).

The less utility is often used not to read text, but to find certain sections in large documents. If you need to find a word, type /text (to search down the text) or ?text (to search less up the text) in the box with the blinking cursor and press Enter. Use standard patterns if necessary. All sections of text that match the specified search conditions will be highlighted in a contrasting color.

If you are interested in how to exit less, then to exit the utility and return to the terminal command line, press q, ZZ or execute another command to signal the end of work. It should be noted that the less utility is intended only for viewing documents.

It does not allow you to edit, format or resave text. The less command in Linux is useful for viewing large text files that are difficult to work with in text editors.