English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux 'less' command

Linux Command大全

Similar to 'more', 'less' can browse files freely, supports pagination and search, and supports scrolling up and down.

Syntax

less [parameter] file 

Parameter description:

  • -b: Set the size of the buffer
  • -e: Automatically exit when the file display is over
  • -f: Force to open special files, such as peripheral device codes, directories, and binary files
  • -g: Only mark the last search keyword
  • -i: Ignore case when searching
  • -m: Display percentage similar to 'more' command
  • -N: Display line numbers for each line
  • -o: Save 'less' output content to a specified file
  • -Q: Do not use warning sound
  • -s: Display consecutive blank lines as one line
  • -S: Discard the exceeding part if a line is too long
  • -x: Display 'tab' key as specified number of spaces
  • /string: Search down for the function of 'string'
  • ?string: Search up for the function of 'string'
  • n: Repeat the last search (with / Or ? (for more information)
  • N: Reverse repeat the last search (with / Or ? (for more information)
  • b: Scroll up one page
  • d: Scroll back half a page
  • h: Display help interface
  • Q: Exit 'less' command
  • u: Scroll up half a page
  • y: Scroll up one line
  • Space key to scroll one page
  • Enter key to scroll one line
  • [pagedown]: Scroll down one page
  • [pageup]: Scroll up one page

Online example

1View file

less log2013.log

2View process information using 'ps' and display with 'less' pagination

ps -ef |less

3View command history usage records and display them in less pagination

[root@localhost test]# history | less
22  scp -r tomcat6.0.32 [email protected]:/opt/soft
23  cd ..
24  scp -r web [email protected]:/opt/
25  cd soft
26  ls
……Omitted……

4Browsing Multiple Files

less log2013.log log2014.log

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

Additional Remarks

1Full Screen Navigation

  • ctrl + F - Move Up One Screen
  • ctrl + B - Move Down One Screen
  • ctrl + D - Move Up Half Screen
  • ctrl + U - Move Down Half Screen

2Single Line Navigation

  • j - Move Up One Line
  • k - Move Down One Line

3Other Navigation

  • G - Move to the Last Line
  • g - Move to the First Line
  • q / ZZ - Exit less Command

4Other Useful Commands

  • v - Edit the current file using the configured editor
  • h - Display less's help document
  • &pattern; - Only display lines that match the pattern, not the entire file

5Mark Navigation

When viewing large files with less, you can mark any position and navigate to the text location marked with a specific mark through the command:

  • ma - Current Position of Text with a Tag
  • 'a - Navigate to Mark a

Linux Command大全