Let's say I open a file with less and look for a pattern such as /time=32, then exit with q, and maybe run other commands. Then, if I open the same file again with less and hit n to repeat the last pattern sought, less remembers it from the first time less was called.

How is the pattern saved after exiting less for the first time? where is it saved?

PS: I am using bash on Ubuntu 12.04

  • 1
    Tip: if the man page and Google don't have the answer to this sort of question, you can see what's changed most recently by going to your home directory and using ls -ltra. (Or ls -lart if you're a BOFH.)
    – Tom Zych
    Dec 3, 2015 at 8:33

2 Answers 2


The pattern is saved in $HOME/.lesshst which contains something like:


A command is preceded by '.' (dot) an the argument is preceded by '"' (double quotes), so if I edit by hand the .lesshst file to append for example the string "TEST:


the next time I'll open a file and press n key, less will search for the string "TEST".


According to the less man page, the default location for the history file is ~/.lesshst:


     Name of the history file used to remember  search  commands  and
     shell  commands  between  invocations of less.  If set to "-" or
     "/dev/null", a  history  file  is  not  used.   The  default  is
     "$HOME/.lesshst"  on  Unix  systems, "$HOME/_lesshst" on DOS and
     Windows systems, or "$HOME/lesshst.ini"  or  "$INIT/lesshst.ini"
     on OS/2 systems.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .