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

This is for a single line, not a command. I found the way to make it always prevent history for a single command.


EDIT: Sorry for the poor wording.

Single line - For example, if I type, git push production, I might not want to accidentally execute this single line in the future, because it should only be run occasionally, and it has serious ramifications.

Command - In this example, the command is git. I would want the history to remember git push; git push staging

Single command - meant command as well.

Is this clearer now? Thanks.

share|improve this question
please clarify what you mean by "single line", "command", and "single command"? The better you phrase your question, the more likely you will be to get a good answer. as it is, this question is somewhat vague. – Tim Kennedy Oct 25 '11 at 4:13
that's much better, thanks for clarifying. i've run into problems a few times, where I just type bash$ !rsync or something, and end up running the wrong rsync account. I can see how being able to keep the git push production command out of your history could be helpful. – Tim Kennedy Oct 25 '11 at 17:05
I've been playing with the HISTIGNORE setting below, and that will do what you want. HISTIGNORE="git push production:&" will tell bash to ignore the git push production command, as well as any duplicate commands (which cleans up history, especially if you run the same tail command or ls command repeatedly) – Tim Kennedy Oct 25 '11 at 17:09
OK, thanks. What does :& do? – B Seven Oct 25 '11 at 17:34
each ARG to HISTIGNORE is separated by :. Much like $PATH. The &, when supplied to HISTIGNORE, tells bash not to log history if the command you just ran is identical to the one before it. It's a serial-deduplicator for shell history, I suppose. – Tim Kennedy Oct 25 '11 at 19:47
up vote 4 down vote accepted

It is not clear what you mean when you contrast "command" and "line". I consider the command to be everything you type at the prompt until the shell interprets it - that's usually until you press enter unless it's inside a quote or escaped. In Bash, the HISTIGNORE environment variable lets you specify a list of patterns; if any of the patterns match the command, it will not record it in the history.

So if your HISTIGNORE contained [ \t]*, any command that started with space or tab would be ignored. That includes each of the following:

echo hi
echo hi; echo there
echo hi; echo there && echo fluffy
echo hi | cat
share|improve this answer
Thanks for the HISTIGNORE tip. :) – Tim Kennedy Oct 25 '11 at 17:10

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.