less Cheat Sheet

Here’s a cheat sheet for working with the less command in Unix/Linux terminals:

Basic Navigation

  • Scrolling:
    • Scroll Up: k or Up Arrow
    • Scroll Down: j or Down Arrow
  • Page Navigation:
    • Next Page: Spacebar
    • Previous Page: b
  • Line Navigation:
    • Next Line: j or Enter
    • Previous Line: k
  • Jump to the Top or Bottom:
    • Go to Top: g
    • Go to Bottom: G

Searching

  • Search Forward:
    • / followed by the search term and Enter
  • Search Backward:
    • ? followed by the search term and Enter
  • Repeat Search:
    • Press n to repeat the search in the same direction.
    • Press N to repeat the search in the opposite direction.

Exiting

  • Quit less:
    • Press q

File Information

  • Display File Name:
    • Press Ctrl + g
  • Display Line Numbers:
    • Press = (equals sign)

Marking and Returning

  • Marking a Position:
    • Press m followed by a letter (e.g., ma)
  • Returning to a Marked Position:
    • Press ' followed by the letter used for marking (e.g., 'a)

Other Options

  • Toggle Line Wrapping:
    • Press - (minus sign)
  • Show Line Numbers:
    • Press : followed by set nu and Enter
    • To hide line numbers, use : followed by set nonu and Enter
  • View Multiple Files:
    • less file1 file2
    • Use :n and :p to navigate between multiple files.
  • View Binary Files:
    • Use less -f to view binary files.

Help

  • Accessing Help:
    • Press h for help within less

Customizing less

  • Configuring Environment Variable:
    • export LESS="-i -M -R -F -X"
    • -i: Ignore case in searches
    • -M: More verbose status line
    • -R: Preserve color escape codes
    • -F: Quit if the content fits on one screen
    • -X: Don’t clear the screen on exit

This cheat sheet covers some of the basic and commonly used commands with the less command in Unix/Linux. Adjust and expand based on your specific needs and preferences.