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

If I perform a sequence of commands like:

$ ls
$ grep abc file.txt

and then use the up arrow key to get the previous one, the terminal will show the last cmd (which is the grep here)

But if I do something like this:

$ ls
$   grep abc file.txt

where grep is preceded by spaces, pressing up gives ls, not grep.

Why is this?

share|improve this question
Follow-up: Why does bash have a HISTCONTROL=ignorespace option? – Gilles Feb 19 '14 at 23:39
up vote 20 down vote accepted

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.

share|improve this answer
and HISTCONTROL is set to ignoreboth in the default ~/.bashrc provided by debian at least. – Stéphane Chazelas Feb 19 '14 at 15:15
What is the use case of ignorespace? – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Sep 28 '15 at 14:30
In Ubuntu 14.04 the default is ignoreboth which is kind-of annoying. – Nick Gammon May 9 at 8:01
Ciro, I assume it's so that you can enter command like echo "drop database mydb" | mysql -u root -pPassword and not have it saved in history. – Jeremy May 30 at 1:04

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.