Skip to content

Bash: Less command and navigate

Michael Watts edited this page Sep 14, 2015 · 1 revision

http://www.thegeekstuff.com/2010/02/unix-less-command-10-tips-for-effective-navigation/

Searching

Forward Search

  • / – search for a pattern which will take you to the next occurrence.
  • n – for next match in forward
  • N – for previous match in backward

Backward Search

  • ? – search for a pattern which will take you to the previous occurrence.
  • n – for next match in backward direction
  • N – for previous match in forward direction

Navigation

Navigating screens

  • CTRL+F – forward one window
  • CTRL+B – backward one window
  • CTRL+D – forward half window
  • CTRL+U – backward half window

Navigating lines

In a smaller chunk of data, where you want to locate particular error, you may want to navigate line by line using these keys:

  • j – navigate forward by one line
  • k – navigate backward by one line

Navigating to beginning or end of file

  • G – go to the end of file
  • g – go to the start of file

Marked navigation

When you are viewing a large log file using less command, you can mark a particular position and return back to that place again by using that mark.

  • ma – mark the current position with the letter ‘a’,
  • 'a – go to the marked position ‘a’.

GO to line(n) navigation

Similar to Vim editor navigation command, you can give 10j to scroll 10 lines down, or 10k to go up by 10 lines.

  • 10j – 10 lines forward.
  • 10k – 10 lines backward.

Other commands

  • q or ZZ – exit the less pager
  • v – using the configured editor edit the current file.
  • h – summary of less commands
  • &pattern – display only the matching lines, not all.
  • CTRL+G – show the current file name along with line, byte and percentage statistics.

SSH

2 Best practices when logging in remotely to linux machine

WARGAMES

Clone this wiki locally