I use bash and I would like to avoid some commands being kept in the history.
- Is it possible to do that for the next command only?
- Is it possible to do that for the entire session?
I use bash and I would like to avoid some commands being kept in the history.
and i just remembered another answer, this one is the actual answer to your question.
if you have "ignorespace" in HISTCONTROL, then bash wont remember any line beginning with a space character. it won't appear even in the current shell's history, let alone be saved to $HISTFILE.
e.g. I have export HISTCONTROL='ignoreboth:erasedups' in my ~/.bashrc
here's the details from the bash man page:
Here's a few history lessons I learned from googling:
You can set the history to ignore certain strings. In this example, I've ignored the commands ls, passwd and any command prefixed by the character space.
To disable history for your session you can issue:
Reference
If you just want to remove the last command from the history, then you can hit Up-arrow, followed by Ctrl - U (erase to beginning of line), then Up-arrow again.
You can erase any individual line from the history like this. Just use up-arrow or search or whatever to make it the current command line being edited, then press Ctrl - U, and then Up-arrow or Down-arrow to move to another history line.
I discovered this by accident one day years ago. I have no idea whether it's documented or not.
Generally, though, it's less hassle to just not save the current shell's history at all with:
You could unset the
HISTFILE
variable. Fromman bash
:I don't think this prevents the command from appearing in the local shell history before the shell exits.
I see that no one wrote this method, so I will.
history -d
deletes the mentioned entry from the history.HISTCMD
stores the command_number of the command to be executed next. So, (HISTCMD-1) refers to the last executed command.After running the command and because it also deletes the command itself then going up with the arrow will not display the command, so if you plan on using that often, it would be best to create an alias:
Then you can do:
I sometimes do