Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I type the following sequence of commands:

$ cd
$ ls
$ ls

When I go back in history by pressing up twice, I end up with cd, instead of ls.

I've noticed this isn't always the case, so it likely is some bash setting somewhere. Which is it?

share|improve this question
up vote 7 down vote accepted

The is controlled by the HISTCONTROL variable. If is contains ignoredups, then duplicate commands will not be saved in the history. Without this string, they will be saved. This would be normally set in .profile or .bashrc, using something like

export HISTCONTROL=ignoredups

Other values that can be used in HISTCONTROL (multiple can be used, separated by :)

  • ignorespace any commands starting with a space are not added to the history
  • erasedups duplicate commands are erased from the history, so the history only contains the latest command
  • ignoreboth identical to ignoredups:ignorespace
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.