13

In most Unix shells, the arrow-up key replaces the command that is being edited by the previous command in the history. The history can be seen using the command history.

can be pressed more than one time to climb up in the history.

My question is:

How can I configure my shell so that skips all commands identical to the current one?

Indeed I often enter many make in a row. When I want to enter again (or modify slightly) an older command I have to hit many times just to skip all the make commands.

I know that is far from being the only tip that increase shell productivity.

bonus:

  • give a configuration working for the Bash shell.
  • preserve the history (knowing that you typed a command many times in a row can be useful)

1 Answer 1

19

For zsh put this in your configuration:

setopt histignoredups

What it does, it will ignore duplicated history entries during search.

The equivalent setting for bash is

HISTCONTROL=$HISTCONTROL:ignoredups
4
  • 1
    thanks, setopt histignoredups does the job but also suppress duplicate from the history Sep 20, 2016 at 21:27
  • Yes, exactly. In most cases this is what you want. When you have seen a suggestion and you don't want it, you don't want to have this suggested again. It does not delete duplicates from history, btw. Sep 21, 2016 at 5:58
  • You are right but I meant: future duplicates will not be added to the history. Sep 21, 2016 at 6:03
  • They are added otherwise the other option called histexpiredupsfirst that I also use would not make sense. It makes duplicates expire first before looking at the age. (I am talking about zsh here) Sep 21, 2016 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.