Last Updated: February 25, 2016
·
2.897K
· mose

Less first

When working on a remote server, I use less instead of tail or vi to check files, the more I can.

filter

  • with &searchstring it will hide all lines not matching searchstring, like a very simple grep from the console
  • just & with nothing to get back to full view

edit file

  • when in less /etc/hosts if I find out I need to edit it I just type v it opens it in vi
  • when you quit the editor you are back in less

follow mode

  • when in less production.log, if you want to follow incoming changes type F it will become like a tail -f but it keeps the syntax highlighting that was made with a / search
  • when in follow mode with F you can ctrl-c any time and examine the new stuff
  • note that if you are in filter mode the follow respects it (like if you did a grep something/var/log/auth.log | grep 'Invalid user')

multifiles

  • you can open several file and navigate like in vim with :n and :p
  • when less is open you can open a new file with :e

call options inside less

  • you can call any launch option from inside less, one I use often is -S that will enable/disable wrapping of long lines, very useful when parsing web server log files
  • to disable/enable search highlighting just -G
  • any other launch option can be called from inside less, pretty convenient

3 Responses
Add your response

I tend to use less almost all the time for viewing files, irrespective of whether I'm doing that on a remote or local server. I'd never used the filter option using the &searchstring, thanks for that tip.

over 1 year ago ·

This is AMAZING. I use less for a big while but didn't know about the &searchstring feature. A BIG THANK YOU!

over 1 year ago ·

Nice to use something as easy as less for filtering instead of having to fire up emacs. It wasn't available on the Mac OS X (Mavericks / 10.9); you'll need version 443 or later for a fully working "&".

over 1 year ago ·