In Linux, the less command is used to browse the contents of a file. The usage of the less command is similar to that of the more command. Unlike the more command, the less command can scroll back to view the contents of a file. The use of less is more flexible than that of more. In more, we do not have the way to turn in front, can only look at the back, but if using less, you can use [pageUp] [pagedown] and other key functions to go back and forth after the file, it is easier to view the content of a file! On top of that, there’s a lot more search functionality in less, not just down, but up.

The command format

Less [Parameter] File

Command function

Less is similar to more, but you can browse files freely. More can only be moved forward but not backward. When more starts, the entire file is loaded. And less doesn’t load the entire file before viewing it.

The command parameter

  • Down arrow, Enter, e, or J — move a row forward.
  • Up arrow, Y or K — move a row backwards.
  • Space Bar is either F – forward one page.
  • B — Move back one page.
  • /pattern – Searches forward for matching patterns.
  • ? Pattern – Searches backwards for matching patterns.
  • N – Repeat the previous search.
  • N – Repeat the previous search in reverse.
  • G – Go to the first line of the file.
  • Ng – Go to line NTH in the file.
  • G – Go to the last line of the file.
  • P — Go to the beginning of the file.
  • Np – N % of incoming files.
  • H – Displays help.
  • Q – Exits less.

Check the file

> less rumenz.txt
Copy the code

Ps Displays process information in less pages

> ps -ef | less
Copy the code

The command usage history is displayed in less pages

> history | less
Copy the code

Browsing multiple files

> less 1.txt 2.txt
Copy the code

Enter n to switch to 1. TXT. Enter p to switch to 2. TXT

Full screen navigation

CTRL + F - Move one screen forward CTRL + B - Move one screen backward CTRL + D - Move one half screen forward CTRL + U - Move one half screen backwardCopy the code

Single navigation

J - move one row forward and K - move one row backCopy the code

Other navigation

G - Move to the last line G - Move to the first line q/ZZ - Exit the less commandCopy the code

The search function

> less/entry rumenz.txt n - Forward to find the next matched text n - Backward to find the previous matched textCopy the code

Original link :rumenz.com/rumenbiji/l…

Wechat official account: entry station