Today's article is another short one - about not saving your input to your Bash history...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,499
Reaction score
9,997
Credits
95,342
I'm getting bored with the short-form articles, so I'd expect the next articles to be longer. Still, some subjects just don't require a long explanation.

This is one of those. If you don't want to save your terminal input to your ~/.bash_history file, it's really easy to do. Not do? Do? Meh... Just read the article...


I do love me some feedback.
 


I would like to see an article that shows you what to do and lists all the logs and other places you must clean up or delete if you accidentally type your password (or something sensitive) as a command in the Terminal.
 
You can close the terminal and edit ~/.bash_history to remove the line with your password in it.

That'd be all you need to do. That's the only place that stores that (normally). This assumes you're using Bash. There are alternatives, like zsh and fish. I'm not 100% sure, but I think those would be similar. I don't bother messing about with other shells.
 
Hey there!

Thanks for sharing this tip on how to prevent a command from being saved in the Bash history. I agree that this method of adding a space before the command is a simple and effective way to keep your history clean, especially when you're experimenting with different commands. I just wanted to add a few more points to this discussion that some users might find helpful.

  1. Another way to prevent a command from being saved in the Bash history is to use the HISTIGNORE environment variable. You can add specific commands or patterns to this variable, and any matching command will not be saved in the history. For example, if you don't want to save any 'ls' command in the history, you can add the following line to your ~/.bashrc file:

Code:
export HISTIGNORE="ls"

After saving the file and reloading the Bash configuration (you can do this by running 'source ~/.bashrc'), any 'ls' command you execute will not be saved in the history.

  1. You can also control the number of commands saved in the history file by setting the HISTSIZE environment variable. By default, it's set to 500, but you can increase or decrease this value based on your preference. To change the value, add the following line to your ~/.bashrc file:

Code:
export HISTSIZE=1000

This example sets the history size to 1000 commands. Don't forget to reload the Bash configuration after modifying the file.

  1. If you ever need to clear your entire Bash history, you can run the following command:

Code:
history -c

This will clear the current session's history. To remove the history file completely, you can delete the ~/.bash_history file using:

Code:
rm ~/.bash_history

Please note that these actions are irreversible, so use them with caution.

These additional tips, along with the method you've shared, should give users more control over their Bash history management. It's always great to learn new tricks to optimize our command-line experience!

Thanks again for sharing your knowledge, and I look forward to more short-form articles or longer ones, whichever you prefer. Your contribution to the community is much appreciated!
 


Latest posts

Top