49

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?

54
echo $HISTCONTROL
ignoreboth

man bash:

HISTCONTROL

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.

  • 3
    and HISTCONTROL is set to ignoreboth in the default ~/.bashrc provided by debian at least. – Stéphane Chazelas Feb 19 '14 at 15:15
  • 1
    What is the use case of ignorespace? – Ciro Santilli 新疆改造中心法轮功六四事件 Sep 28 '15 at 14:30
  • 1
    In Ubuntu 14.04 the default is ignoreboth which is kind-of annoying. – Nick Gammon May 9 '16 at 8:01
  • 6
    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 '16 at 1:04
  • 2
    For mac users, HISTCONTROL is not set to anything, so you'll need to add it to your bash_profile or similar - unix.stackexchange.com/questions/115917/… – chrismarx Dec 26 '18 at 19:00

Your Answer

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

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