less is a Linux command-line utility that is used to display the contents of a file or command output, which displays only a page. It is similar to more, but with more advanced features that allow you to navigate forward and backward in a file.
The less command is used to open large files. less will not read the entire file, such as compared to vim or nano text editor, load times will be faster.
How to use less
The general syntax less command is as follows:
less [OPTIONS] filename
For example, to view the / usr / share file content / common-licenses / GPL-3, you want to enter:
less /usr/share/common-licenses/GPL-3
You can also pipe the command to redirect the output to less. For example, to page through the output of the command ps, type:
ps aux | less
Browse file contents
When you open the contents of the file is too large to fit into one page, you will see a colon (:).
To go to the next page, please f button or the spacebar. If you want to move down a certain number of lines, type a number, followed by a space or f button.
You can scroll down one line press the Enter key or backward, rolling forward through the line up key.
To return to the previous page, b button. By typing a number followed by b to move up a specific number of lines.
If you want to search mode, type /, and then type the pattern to search for. Once you press the Enter key, less matches will search forward. Backward search use? Followed by a search mode.
When the end of file, the string (the END) shown at the bottom.
To exit less and return to the command line, press q.
less options
If you want less display line numbers, use the following -N option to start the program:
less -N filename
By default, when less exit from the screen to clear the file contents. To preserve the contents of a file on the screen, use the following -X options:
less -X filename
The + F option tells you to view the contents of files less likely to change. This is useful when you open the log file.
less +F /var/log/messages
Added option F + less of performance is almost the same with the tail -f command.
less command
The program includes many less command, allows you to browse the contents of the file and search string. If you want to see a complete list of all commands, use the h.
Here are some of the most commonly used commands for browsing the file content when less Views:
command | action |
---|---|
Down arrow, enter, e, or j | Forward line. |
Down arrow, y k, or | Backed up one row. |
Spaces or f | Move forward one page. |
b | Move back one page. |
/pattern | Forward match search mode. |
? pattern | Backward search for a matching pattern. |
n | Repeat the last search. |
N | Inverted repeat the last search. |
g | Go to the first line of the file. |
of | Go to line N in the file. |
G | Go to the last line of the file. |
p | Go to the beginning of the ile. |
For example, | Go into the archives N%. |
h | Displays help. |
q | Exit less. |
in conclusion
By now, you should have a good understanding of how to use the less command.