20

Every time I search for a term in less, it stores my search in the file .lesshst. How can I stop this behavior?

3 Answers 3

23

Open a terminal and create a file .lesskey, in your home folder and append the following to it:

#env
LESSHISTSIZE=0

If you already have the file .lesshst in your home folder, then delete it and type the command

lesskey

You shouldn't get any errors here. This will not store any history of less from now on, until you change the .lesskey file.

From the man page of less:

ENVIRONMENT VARIABLES

   Environment variables may be specified either in the system environment
   as usual, or in a lesskey  (1)  file.   If  environment  variables  are
   defined  in  more  than one place, variables defined in a local lesskey
   file take precedence over variables defined in the system  environment,
   which take precedence over variables defined in the system-wide lesskey
   file.

LESSHISTSIZE

          The maximum number of commands to save in the history file.  The
          default is 100.

EDIT:

From the comments, I found a better way to prevent having a history file for less.

In the .lesskey file in the home folder, append this:

LESSHISTFILE=-

or

LESSHISTFILE=/dev/null

If you put this in your ~/.bashrc file, this will work, but will have a lower precedence if you have other values in your .lesskey file for the same variables.

You may want to have a look at this:

3
  • 3
    @InkBlend Did you use export? I neuter less in my .bashrc with: "export LESSHISTFILE=/dev/null" Commented Dec 6, 2013 at 19:46
  • 1
    Perhaps @Jobin could add the .bashrc + export to his answer. I think he deserves the credit for a good answer. Commented Dec 11, 2013 at 18:47
  • Great. Get rid of the .lesshst file and add a .lesskey file instead. Set environment variable to LESSSECURE=1 and it won't use lesskey file or less history file. Or just compile it with the secure option and you don't have to have the environment variable either.
    – NeilG
    Commented Aug 5, 2023 at 7:29
1

Add this to your ~/.bashrc:

export LESSHISTFILE=-

To verify, you can now start a new shell, delete the ~/.lesshist file, and then start using less. It should not create a new ~/.lesshist file again.


Note that the export is important. If you leave it out, the LESSHISTFILE variable appears to be set (echo $LESSHISTFILE will output -), but it will not be passed to less.

0

This is basically a bash trick incorporating the LESSHISTFILE override via command prefix environment manipulation.

history | LESSHISTFILE=/dev/null less

What this does is pipe the output of the history command into less while using a command prefix to manipulate the environment exposed to the less command.

This is described in the bash reference as:

The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described in Shell Parameters. These assignment statements affect only the environment seen by that command.

More about that specific use at https://stackoverflow.com/a/52208927/117471

You must log in to answer this question.

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