5
  HIST_FIND_NO_DUPS
         When searching for history entries in the line editor, do not display duplicates of a line previously found, even if  the  duplicates  are  not contiguous.

However, when I use Ctrl-p repeatedly, same command appears.

$ ls
$ pwd
$ ls
$ <Ctrl-p> => ls 
  <Ctrl-p> => pwd
  <Ctrl-p> => ls  again!

zsh 5.0.5 (x86_64-apple-darwin14.0)

2 Answers 2

7

hist_find_no_dups doesn't guarantee that all lines will by unique, you might be searching back through repeated pair of lines.

If you don't want to have duplicate lines then look into hist_ignore_all_dups. It will stop repeated commands from appearing in your history file but it might introduce unexpected gaps - something to be aware of if you're reusing parts of your history.

Another option to look into is hist_ignore_dups. This prevents consecutive duplicates from being saved.

Last, but not least, there's hist_save_no_dups (ignores duplicates when writing history file) and hist_expire_dups_first, which will start removing repeating commands when limit of $HISTSIZE will be reached.

1

Ctrl-P is the same as up arrow, it allows you to access previous commands written in history.

HIST_FIND_NO_DUPS makes an effect when you search for previous commands by pressing Ctrl+R, it will skip duplicates.

1
  • Ie, if you enter commands, cd ~/Downloads, cd, cd ~/Download, cd /. Then hit Ctrl-r, type cd then hit Ctrl-r to cycle though matches, you will only see cd ~/Downloads appear once if you have set HIST_FIND_NO_DUPS Commented Jan 11, 2023 at 2:02

You must log in to answer this question.

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