Usage of less commands in linux (content displayed on pages)

Source: Internet
Author: User
The less tool is also a paging display tool for files or other outputs. it should be said that it is an Orthodox linux tool for viewing file content and has extremely powerful functions. The usage of less is more flexible than that of more

The less tool is also a paging display tool for files or other outputs. it should be said that it is an Orthodox linux tool for viewing file content and has extremely powerful functions. The usage of less is more flexible than that of more. At the time of more, we could not flip forward, but we could only look at it later. However, if less is used, you can use the [pageup] [pagedown] and other buttons to access and view the file, making it easier to view the content of a file! In addition, you can have more search functions in less, not only to search down, but also to search up.

1. command format:

Less [parameter] file

2. command functions:

Less is similar to more, but less can be used to browse files at will, while more can only move forward, but cannot move backward, and less will not load the entire file before viewing.

3. command parameters:

-B <缓冲区大小> Set the buffer size
-E automatically leaves after the file is displayed.
-F Forces special files to be opened, such as peripheral device codes, directories, and binary files.
-G only indicates the last keyword to be searched.
-I ignore the case when searching
-M: Display the percentage of more commands.
-N: displays the row number of each row.
-O <文件名> Save the less output content in the specified file
-Q: No warning sound is used.
-S: displays a row of empty rows.
The-S line will discard the excess part after a long time
-X <数字> Display the "tab" key as a specified number space
/String: the function of searching "string" down
? String: the "string" search function
N: Repeat the previous search (and/or? Related)
N: Repeat the previous search (and/or? Related)
B. flip one page backwards.
D. flip back half page
H. display the help page
Q: exit the less command
U scroll forward half page
Y: scroll one row forward.
Space key to scroll a row
Enter key to scroll one page
[Pagedown]: scroll down a page
[Pageup]: returns a page up.

4. example:

Instance 1: View files
Command:
Less log2013.log

Output:

 

Instance 2: View process information in ps and display it on the less page

Command:
Ps-ef | less

Output:



Instance 3: view the Command History and display it on the less page

Command:

History | less

Output:


Copy codeThe code is as follows:
[Root @ localhost test] # history | less
Scp-r tomcat6.0.32 root@192.168.120.203:/opt/soft
Cd ..
Scp-r web root@192.168.120.203:/opt/
Cd soft
Ls
Scp-r maid _ 16/root@192.168.120.203:/opt/soft
Clear
Vim/etc/profile
Vim/etc/profile
Cd tomcat6.0.32/bin/
Ls
./Shutdown. sh
./Startup. sh
Vim startup. sh
Ls
Echo $ JAVA_HOME
Java
Ls
Ls
Clear
Cd/opt
Ls
Cp apache-tomcat-6.0.32.tar.gz soft/
Ls
Rm-f apache-tomcat-6.0.32.tar.gz
Ls
Cd soft
Ls
Tar-vzf apache-tomcat-6.0.32.tar.gz
Tar-vzfx apache-tomcat-6.0.32.tar.gz
Tar-zxvf apache-tomcat-6.0.32.tar.gz
Ls
Cd apache-tomcat-6.0.32
Ls
Cd ..
Mv apache-tomcat-6.0.32 tomcat6.0.32
Ls
Cd tomcat6.0.32/
Ls


Example 4: browse multiple files

Command:

Less log2013.log log2014.log

Output:



Note:

Input: n, switch to log2014.log
Input: p, switch to log2013.log

5. Additional remarks

1. Full-screen navigation

Ctrl + F-move the screen forward
Ctrl + B-move one screen backward
Ctrl + D-move the half screen forward
Ctrl + U-move the half screen backward
 
2. single-row navigation

J-move a row forward
K-move a row backward
 
3. other navigation

G-move to the last row
G-move to the first line
Q/ZZ-exit the less command
 
4. other useful commands

V-use the configuration editor to edit the current file
H-show the less help document
& Pattern-only show matching mode rows, not the entire file
 
5. Mark navigation

When you use less to view large files, you can mark them at any location. you can use commands to navigate to the text location marked with a specific tag:
Ma-mark the current position of the text with
'A-navigate to mark

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.