More with less

Here are a few tricks I use every day with GNU less.

Non-interactive usage:

  • less -MI — this is how I usually invoke less; it displays more verbose prompt (like more), showing percentage of the file, along with case-insensitive search
  • less -bN — use N KBs as input buffer; by default 64KB
  • less -B — disables automatic allocation of large buffers for large reads from pipes, and use 64KB or whatever is specified with -b
  • grep –color=always pattern /var/log/app/debug_log | less -SR — do not fold long lines, and show colors

Interactive usage:

  • less uses a lot of vim commands
  • -I — case-insensitive search
  • F — follow for changes (don’t need to exit, and tail -f)
  • &pattern — only display lines that match a pattern
  • m<lower case letter> — mark this position with lower case letter
  • ‘<lower case letter> — go to the position marked with lower case letter
  • v — open $EDITOR to edit the file

Comments are closed.