Linux less Command

Linux 命令大全Linux Command Reference

less is similar to more. less allows you to browse files freely, supports paging and searching, and supports paging up and paging down.

Syntax

less [参数] 文件 

Parameter Description:

  • -b <buffer size> Set the size of the buffer
  • -e Automatically exit when the file display ends
  • -f Force opening of special files, such as peripheral device codes, directories, and binary files
  • -g Only flag the last searched keyword
  • -i Ignore case when searching
  • -m Display percentage similar to the more command
  • -N Display the line number for each line
  • -o <file name> Save the output of less to the specified file
  • -Q Do not use warning sounds
  • -s Display consecutive blank lines as a single line
  • -S Discard the overflow part when lines are too long
  • -x <number> 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 page
  • d Page down half a page
  • h Display the help interface
  • Q Exit the less command
  • u Scroll forward half a page
  • y Scroll forward one line
  • Spacebar Scroll one page
  • Enter key Scroll one line
  • [pagedown]: Page down one page
  • [pageup]: Page up one page

Examples

1. View a file

less log2013.log

2. Use ps to view process information and display it page by page with less

ps -ef |less

3. View command history usage records and display them page by page 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 using the configured editor
  • h - Display the less help documentation
  • &pattern - Only display lines matching the pattern, not the entire file

5. Marker navigation

When using less to view large files, you can place markers at any position and navigate to text positions marked with specific markers via commands:

  • ma - Mark the current position of the text with a
  • 'a - Navigate to marker a

Linux 命令大全Linux Command Reference

Other Extensions