Linux less command
less is similar to more, but less lets you browse files freely, supporting paging and searching, as well as paging up and down.
Syntax
less [参数] 文件
Parameter Description:
- -b
set the buffer size - -e automatically exit when the end of the file is reached
- -f force-open special files such as device files, directories, and binary files
- -g highlight only the last searched keyword
- -i ignore case when searching
- -m display the percentage like the more command
- -N display line numbers for each line
- -o
save the content output by less to a specified file - -Q do not use the warning bell
- -s display consecutive blank lines as a single line
- -S discard the overflow when a line is too long
- -x
display the "tab" key as the specified number of spaces - /string: search downward for "string"
- ?string: search upward for "string"
- n: repeat the previous search (related to / or ?)
- N: repeat the previous search in reverse (related to / or ?)
- b page up one screen
- d page down half a screen
- h display the help screen
- Q exit the less command
- u scroll forward half a screen
- y scroll forward one line
- spacebar scroll one page
- Enter key scroll one line
- [pagedown]: page down one screen
- [pageup]: page up one screen
Example
1. View a file
less log2013.log
2. Use ps to view process information and page through it with less
ps -ef |less
3. View command history and page through it 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
……省略……
4. Browse multiple files
less log2013.log log2014.log
Explanation:
After entering :n, switch to log2014.log
After entering :p, switch to log2013.log
Additional notes
1. 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
2. Single-line navigation
- j - next line
- k - previous line
3. Other navigation
- G - move to the last line
- g - move to the first line
- q / ZZ - exit the less command
4. Other useful commands
- v - edit the current file with the configured editor
- h - display the help documentation for less
- &pattern - display only lines matching the pattern, not the whole file
5. Mark navigation
When using less to view a large file, you can mark any position and navigate via commands to the text location marked with a specific mark:
- ma - mark the current text position with a
- 'a - navigate to mark a
Linux Command Reference