How to use “less” efficiently

The Linux / Unix less and more tools are called pagers. The pagers are used for navigating through text files and commands outputs.

In this article I will show you some less shortcuts (tricks) that will make your navigation easier:

$ less /etc/passwd

A few usefull less tricks:

Search shortcuts:

  • Search forward: /  ;  example: /keyword
  • Search backwords: ? ; example: ?keyword

To jump forward to the next keyword found , press n. To jump backwards, press N.

Show only lines that match a pattern: &/ ; example: &/pattern

Open the file in the default editor: v

Navigate through less:

  • Go to the beggining of the file: gg
  • Go to the end of the file: G
  • Half page up: u
  • Half page down: d
  • Single line up: k
  • Single line down: j
  • Forward one page: Ctrl – F
  • Backwards one page: Ctrl – B

Display line numbers in less : less -N /path/to/file

$ less -N /etc/passwd

Multiple file opening: less file1 file2

Navigation across files:

  • Next file: :n
  • Previous file: :p

Exit the less pager: q

Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!