Ubuntu: After removing .bash_history?


After I remove .bash_history, will .bash_history ever be recreated again? If so what creates it after it has been removed?


See the "invocation" section of bash's manual (man bash).

Put set +o history in either /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile, or ~/.bashrc. The 1st one is for all users, and the others are for 1 user. ~/.profile should always be there so use that one.

You still need to remove the current history file. history -c clears it but will leave an empty file so remove ~/.bash_history with rm.


I don't know, what happens if you remove the file. I guess a new version will be created. If not, you can create it manually,

touch ~/.bash_history  

Sometimes I happen to enter a password or other sensitive information incorrectly, so that it will be saved in the file .bash_history. Then I will edit the file and remove the sensitive information (the corresponding line(s)) and save the file. (Edit: I will close all terminal windows, set the file browser to show hidden files and start editing via the file browser.)

I want to keep the main part of the history, because it makes things easier, so I would not remove the file.

I have even made a couple of script files to search the bash history quickly with a search string as parameter.

HI (HIstory),

history|grep "$*" |sed 's/^ *//' |tr -s ' ' ' '|cut -d ' ' -f2-  

HIT (HIstory Tail),

history|grep "$*" |sed 's/^ *//' |tr -s ' ' ' '|cut -d ' ' -f2- |tail  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »