The less command in Linux uses

Source: Internet
Author: User


The difference between less and cat and more:

The Cat command feature is used to display the contents of the entire file using no paging function, so it is often used with the more commands, and the Cat command is the ability to merge several files into one file.
More command function: Let the screen display full page when the pause, at this time can press the empty SPACEBAR continue to display the next screen, or press the Q key to stop the display.


Less command function: The less command is similar to the more command and can be used to browse over a page of files. The difference is that the less command, in addition to pressing the SPACEBAR to display the file down, can also use the up and down keys to scroll the file. When you want to end the browsing, simply press the Q key under the ":" Prompt in the less command.
In fact, these three commands, in addition to the cat command has the ability to merge files, the rest of the function is similar, but from the browsing habits and display different ways.


The navigation command in less is similar to VI, as follows:
1. Search
When you open a file using the command less file-name, you can search for it in the file using the following method. The matching portions of the entire text are highlighted when searching.

1) Forward Search
/: Search with a pattern and navigate to the next matching text
N: Find the next matching text forward
N: Find the previous matched text backwards
2) Search backwards
? : Searches using a pattern and navigates to the previous matching text
N: Find the next matching text backwards
N: Forward search for previous matched text

2. Full Screen navigation
CTRL + F: Move one screen forward
CTRL + B: Move backward one screen
CTRL + D: Move forward half screen
CTRL + U: Move back half screen

3. Single-line navigation
J: Move forward one line
K: Move backward one line
4 other navigation
G: Move to the last line
G: Move to the first line
Q/zz: Exit less command

5. Edit the file

V: Enter edit mode to edit the current file using the configured editor
The default editing mode is the Nano Editor, note that in the Nano Help document, Ctrl-key is represented as a caret (^), so Ctrl+w is written as ^w, and so on. The alt-key is represented as a m (from "Meta"), so Alt+w is written as a m-w.


6. Tag Navigation
When you use less to view large files, you can mark them in any location, and you can navigate to the text location labeled with a specific tag by command.
MA: Use A to mark the current position of the text
' A: Navigate to mark A

7. Browse Multiple Files
Way One
By passing multiple parameters to less, you can browse multiple files.

Less file1 file2

Way Two

When you are browsing a file, use: E to open another file.

Less file1

: E file2
When you open multiple files, use the following command to switch between multiple files
: N-Browse next file Nextfile
:p-View the previous file Previousfile

Version 8.less tail-f

In Linux dynamic View log files commonly used commands are not tail-f, in fact less can also do this work, using the F command. Use less file-name to open the log file, execute command F, you can achieve a similar tail-f effect

The less command in Linux uses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.