Linux less command: view the file contents

More action and less command is very similar, are used to browse the contents of a text file, except that, when using more command browse file contents, can only continue to look backwards, while using less command to navigate, either backwards look, you can also look forward.

 

Moreover, in order to respect users to browse the text content, less command also provides the following functions:

  • Use the cursor keys to scroll back and forth in the text file (left rear);
  • Line number or as a percentage of browser bookmarks file;
  • Provide more user-friendly search, highlight and other operations;
  • Compatible with conventional word processing programs (such as Vim, Emacs) of the keyboard;
  • At the end of reading the file, less command does not quit;
  • Message alert at the bottom of the screen easier to control use and provides more information.

Less command basic format is as follows:

[Root @ localhost ~] # less [options] filename

This option is available commands and a respective meanings as shown in Table 1.

Table 1 less command options and their meanings
Options Option Meaning
-N Display line numbers for each line.
-S The excess discarded when the line is too long.
-e After the end of the file is displayed, automatically leave.
-g Only sign a key with the last search.
-Q Without the use of a warning tone.
-i Ignore case when searching.
-m It shows the percentage is similar to the more command.
-f Forced to open a special file, such as a peripheral device code, binary files and directories.
-s Display continuous line empty behavior.
-b <buffer size> Set the buffer size.
-o <filename> Save the content less output to the specified file.
-x <number> The [Tab] key to display the digital space as specified.

In the process of using the less command to view file contents, and more commands, it will enter the interface, requiring the reader to have some common interaction command, as shown in Table 2.

Table 2 less interaction instruction and function
Interactive instruction Features
/ String Down "character string" function.
? String Search up "strings" function.
n * Repeat previous search (with / as? Relevant).
N Inverted repeats before a search (and / or?-Related).
b An upward movement.
d Half a page is moved downward.
h or H Displays help screen.
q or Q Exit the less command.
Y Moves up one line.
space bar Move down one page.
enter Move down one line.
[PgDn] key Move down one page.
[PgUp] key An upward movement.
Ctrl+f Move down one page.
Ctrl+b An upward movement.
Ctrl+d Move down one page.
Ctrl+u Up half a page.
j Move down one line.
k Moves up one line.
G Move to the last line.
g To the first line.
ZZ Exit the less command.
v Using the configuration editor to edit the current file.
[ Moved to a node of the present document.
] Moving to the next node in the present document.
p Moved to a peer node.
in Up half a page.

[Example 1] use the less command to view the contents /boot/grub/grub.cfg file.

[root@localhost ~]# less /boot/grub/grub.cfg
#
#DO NOT EDIT THIS FILE
#
#It is automatically generated by grub-mkconfig using templates from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="0"
if [ "$ {prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry= save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
:

可以看到,less 在屏幕底部显示一个冒号(:),等待用户输入命令,比如说,用户想向下翻一页,可以按空格键;如果想向上翻一页,可以按 b 键。

推荐学习目录: Linux head

Guess you like

Origin blog.csdn.net/uyhuayussd/article/details/94723215