10

I'd like for the mac os terminal app to scroll through my command history the same way that it work in linux, if possible. Currently, if I push the up arrow in the terminal, it will scroll through each and every one of my recent commands even if the last 50 were the same exact command. On most linux systems I've used, this behavior will scroll backwards through command history, but most importanlty it will skip duplicate commands. Is this behavior possible in Mac OS X terminal app, or do I need to use a different terminal app? Thanks.

  • 2
    This is not the action of the Terminal app but how you have set up your shell - probably bash see its documentation for history – Mark Oct 23 '15 at 18:33
  • Also check out iTerm2. IMO it's a better tool. iterm2.com – Harv Oct 27 '15 at 22:22
8

Mark who commented on my questions above was correct. This is a bash setting. If you add the following to your ~/.bash_profile script, you will get this behavior.

HISTCONTROL=ignoredups

You can also ignore any lines that start with a space:

HISTCONTROL=ignorespace

Or do both, by using:

HISTCONTROL=ignoreboth
  • 1
    Strictly better add to .bashrc and make .bash_profile source .bashrc - see bash manual – Mark Oct 23 '15 at 19:14
3

Assuming that you are using bash then

HISTCONTROL=ignoreboth

or

HISTCONTROL=ignoreboth:erasedups

in one of your bash rc file(s).

You must log in to answer this question.

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