Linux less Command
less is similar to more, but it allows for arbitrary browsing of files, supports paging and searching, and allows for both forward and backward paging.
Syntax
less [options] file
Parameter Description:
-b <buffer size> Set the size of the buffer
-e Automatically exit when the file display is complete
-f Force open special files, such as device numbers, directories, and binary files
-g Only highlight the last searched keyword
-i Ignore case when searching
-m Display the percentage similar to the more command
-N Display the line number for each line
-o <filename> Save the output of less to a specified file
-Q Do not use warning sounds
-s Display consecutive blank lines as one line
-S Truncate long lines
-x <number> Display "tab" keys as a specified number of spaces
/string: Function to search for "string" forward
?string: Function to search for "string" backward
n: Repeat the previous search (related to / or ?)
N: Repeat the previous search in reverse (related to / or ?)
b Scroll up one page
d Scroll back half a page
h Display the help interface
Q Exit the less command
u Scroll forward half a page
y Scroll forward one line
Space bar Scroll one page
Enter key Scroll one line
[Page Down]: Scroll down one page
[Page Up]: Scroll up one page
Examples
View a file
less log2013.log
Display process information with ps and paginate with less
ps -ef | less
View command history and paginate with less
[root@localhost test]# history | less 22 scp -r tomcat6.0.32 root@192.168.120.203:/opt/soft 23 cd .. 24 scp -r web root@192.168.120.203:/opt/ 25 cd soft 26 ls ……omitted……
Browse multiple files
less log2013.log log2014.log
Additional Notes
- Full-screen navigation
ctrl + F - Move forward one screen
ctrl + B - Move backward one screen
ctrl + D - Move forward half a screen
ctrl + U - Move backward half a screen
- Single-line navigation
j - Next line
k - Previous line
- Other navigation
G - Move to the last line
g - Move to the first line
q / ZZ - Exit the less command
- Other useful commands
v - Edit the current file with the configured editor
h - Display the less help documentation
&pattern - Only display lines matching the pattern, not the entire file
- Mark navigation
When viewing large files with less, you can mark any position and navigate to the marked text position with commands:
ma - Mark the current position with 'a'
'a - Navigate to the marked 'a' position