Assum I have the following command history:

  • A
  • B
  • B

When pressing the up arrow on most linux terminals this would cycle like:

  • B
  • A

On osx terminal however it got me:

  • B
  • B
  • A

How can I regain the former behaviour?

2 Answers 2



export HISTCONTROL=ignoreboth:erasedups

to ~/.bash_profile worked for me.

  • That was it. Thank you for taking the time to answer an old unanswered question.
    – magu_
    Oct 24, 2019 at 10:58

From man bash:

A colon-separated list of values controlling how commands are saved on the history list. If
the list of values includes ignorespace, lines which begin with a space character are not
saved in the history list. A value of ignoredups causes lines matching the previous history
entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. 
A value of erasedups causes all previous lines matching the current line to be removed from
the history list before that line is saved. Any value not in the above list is ignored.

To mimic the behavior you are used to, run echo $HISTCONTROL on your Linux system and then set the same value on your Mac.

You must log in to answer this question.

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