71

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?

1

1 Answer 1

79
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.

6
  • 4
    and HISTCONTROL is set to ignoreboth in the default ~/.bashrc provided by debian at least. Feb 19, 2014 at 15:15
  • 2
    What is the use case of ignorespace? Sep 28, 2015 at 14:30
  • 2
    In Ubuntu 14.04 the default is ignoreboth which is kind-of annoying. May 9, 2016 at 8:01
  • 12
    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, 2016 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, 2018 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.