I'd like to prevent commands that are already present in .bash_history on macOS from being added again if reentered in Terminal (usually by typing the first few characters and scanning back in history).

I have tried

  • export HISTCONTROL=erasedups:ignorespace
  • export HISTCONTROL=ignoredups:ignorespace

and even

  • export HISTCONTROL=erasedups: ignoreboth

But what I get is a single entry for each session rather than across sessions: i.e., if a command is already in .bash_history at the start of a session, and it's typed again, it will be added to history (though only once for that session). How do I ensure that a command that's already in `.bash_history when I launch Terminal isn't added if it's entered again?

Your Answer

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

Browse other questions tagged or ask your own question.