3

I don't want it to do it to my system, but I am wondering, is it possible to delete .bash_history?

And if yes, then can you bring it up again or there will be no history ever again?

Also, is the history command using the .bash_history file?

  • 1
    -1 just for asking this. Testing such kind of stuff can be safely done on your system. Just back-up the file and try to delete it. – Quora Feans Sep 12 '15 at 23:45
  • 2
    @QuoraFeans I agree with you, but maybe he thought this file is required by bash and he was afraid of not being able to login to shell again without this file. – jingyu9575 Sep 13 '15 at 4:17
7

is it possible to delete .bash_history

Sure, it's a file, you can delete it!

Can I delete .bash_history without sudo?

Yes, without sudo, assuming you are talking about deleting your own .bash_history. It's your own file, you have permissions on your own home directory.

Then can you bring it up again or there will be no history ever again ?

ever again? Nothing that drastic! Your history up to now will be gone, yes, but new commands you enter will begin to be recorded in (a new instance of) the file.

Also, Is the history command using the .bash_history file ?

The contents are cached in memory by the shell, but yes, ultimately, that is where the history is loaded from.

| improve this answer | |
  • so if i delete .bash_history, it will eventually be created again ? – alkabary Sep 12 '15 at 19:56
  • Yes. Typically this will happen when any of your interactive shells exit. – Celada Sep 12 '15 at 19:58
  • Actually, it is possible to switch that off, with set -o nohistory. If you enter that command interactively it's only valid for your current shell; if you want to make the change permanent' you should add it to one of your shell's startup scripts (e.g., .bashrc). I don't recommend that however, as shell history is a useful feature. – Wouter Verhelst Sep 12 '15 at 22:46
  • 3
    @alkabary If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. I notice that you haven't accepted any answers for a while, if you have simply forgotten, please go and check your older questions and accept any answers that solved your problem. – terdon Sep 12 '15 at 23:12
3

Yes, you can, from the login shell.

cd
exec /bin/rm .bash_history
| improve this answer | |
  • 1
    Ah yes, you'll need to exec out of your shell if your shell is bash and if you want the file to stay deleted after you delete it. – Celada Sep 12 '15 at 19:57

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.