MacOS – How to set the Mac OS X terminal history to act like linux when using up/down arrows

command linemacosterminal

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.

Best Answer

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