why deleting bash history is not enough?












13















I used to think deleting my bash history was enough to clear my bash history, but yesterday my cat was messing around the right side of my keyboard and when I got back into my computer I saw something I typed a month ago, then I started to press all the keys like crazy looking for what could've triggered it. Turns out UPARROW key shows my bash history even after deleting .bash_history.



How can I delete my bash history for real?










share|improve this question


















  • 8





    .bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

    – Shadur
    Jan 13 '18 at 14:05






  • 12





    Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

    – cas
    Jan 14 '18 at 3:57











  • @cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

    – bunden
    Jan 14 '18 at 15:31













  • Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

    – cas
    Jan 14 '18 at 16:14













  • @cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

    – bunden
    Jan 14 '18 at 16:51


















13















I used to think deleting my bash history was enough to clear my bash history, but yesterday my cat was messing around the right side of my keyboard and when I got back into my computer I saw something I typed a month ago, then I started to press all the keys like crazy looking for what could've triggered it. Turns out UPARROW key shows my bash history even after deleting .bash_history.



How can I delete my bash history for real?










share|improve this question


















  • 8





    .bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

    – Shadur
    Jan 13 '18 at 14:05






  • 12





    Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

    – cas
    Jan 14 '18 at 3:57











  • @cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

    – bunden
    Jan 14 '18 at 15:31













  • Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

    – cas
    Jan 14 '18 at 16:14













  • @cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

    – bunden
    Jan 14 '18 at 16:51
















13












13








13


5






I used to think deleting my bash history was enough to clear my bash history, but yesterday my cat was messing around the right side of my keyboard and when I got back into my computer I saw something I typed a month ago, then I started to press all the keys like crazy looking for what could've triggered it. Turns out UPARROW key shows my bash history even after deleting .bash_history.



How can I delete my bash history for real?










share|improve this question














I used to think deleting my bash history was enough to clear my bash history, but yesterday my cat was messing around the right side of my keyboard and when I got back into my computer I saw something I typed a month ago, then I started to press all the keys like crazy looking for what could've triggered it. Turns out UPARROW key shows my bash history even after deleting .bash_history.



How can I delete my bash history for real?







linux bash bashrc






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 13 '18 at 13:58









bundenbunden

8818




8818








  • 8





    .bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

    – Shadur
    Jan 13 '18 at 14:05






  • 12





    Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

    – cas
    Jan 14 '18 at 3:57











  • @cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

    – bunden
    Jan 14 '18 at 15:31













  • Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

    – cas
    Jan 14 '18 at 16:14













  • @cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

    – bunden
    Jan 14 '18 at 16:51
















  • 8





    .bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

    – Shadur
    Jan 13 '18 at 14:05






  • 12





    Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

    – cas
    Jan 14 '18 at 3:57











  • @cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

    – bunden
    Jan 14 '18 at 15:31













  • Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

    – cas
    Jan 14 '18 at 16:14













  • @cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

    – bunden
    Jan 14 '18 at 16:51










8




8





.bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

– Shadur
Jan 13 '18 at 14:05





.bash_history is overwritten every time you close a bash shell. So if you start bash, delete .bash_history, and log off, you'll have accomplished exactly nothing.

– Shadur
Jan 13 '18 at 14:05




12




12





Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

– cas
Jan 14 '18 at 3:57





Your cat deserves a huge reward. You've been using bash for how long without discovering it has command-line recall and editing? Do you just retype every command line from scratch every time or something? That would make the shell very unpleasant to use.

– cas
Jan 14 '18 at 3:57













@cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

– bunden
Jan 14 '18 at 15:31







@cas ten years. Now that you say it I press Uparrow to repeat commands, but I understood it as kind of a 'short term' memory no more than a few lines long. I wasn't warned that deleting .bash_history won't delete bash history.

– bunden
Jan 14 '18 at 15:31















Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

– cas
Jan 14 '18 at 16:14







Deleting ~/.bash_history really does delete ~/.bash_history....but (unless you take steps to prevent it, like clearing the in-memory history by running history -c just before you logout or setting HISTFILE=/dev/null or just unseting it) bash will just save its current history again when it exits. BTW, the HISTSIZE env var tells bash how many lines of history to keep in memory, and HISTFILESIZE tells bash the maximum number of history lines to save. both of these can be set in, e.g., your ~/.bashrc. PS: your cat deserves a 2nd reward for teaching you a valuable lesson :)

– cas
Jan 14 '18 at 16:14















@cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

– bunden
Jan 14 '18 at 16:51







@cas I think deleting .bash_history should delete bash history. It seems intuitive to me. What it doesn't seem intituive is history -c, history -w, unsetting variables.. that's nuts from the user experience perspective.

– bunden
Jan 14 '18 at 16:51












4 Answers
4






active

oldest

votes


















22














Doing a:



$ history -c; history -w


Will clear history in memory and write that to the HISTFILE file.

That will clear both memory and file history.



If it is required that nothing else of the present session would be written to the history, then, unset HISTFILE will prevent any such logging.






share|improve this answer


























  • And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

    – Michael Hampton
    Jan 14 '18 at 3:15











  • @MichaelHampton Detail added. Thanks.

    – Isaac
    Jan 14 '18 at 3:46






  • 1





    Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

    – Mikko Rantalainen
    Apr 9 '18 at 10:52



















9














bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.



If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.



Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.






share|improve this answer



















  • 3





    A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

    – Isaac
    Jan 13 '18 at 15:20





















0














While leaving the shell, do it all in once, like
echo "" > ~/.bash_history & history -c & exit






share|improve this answer








New contributor




user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




























    -1














    "How can I delete my bash history for real?"



    Exit bash, start a different shell, delete the bash history file.



    or



    logout, log into a different account that has write permission on the history file, delete the history file.






    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "106"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416820%2fwhy-deleting-bash-history-is-not-enough%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      22














      Doing a:



      $ history -c; history -w


      Will clear history in memory and write that to the HISTFILE file.

      That will clear both memory and file history.



      If it is required that nothing else of the present session would be written to the history, then, unset HISTFILE will prevent any such logging.






      share|improve this answer


























      • And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

        – Michael Hampton
        Jan 14 '18 at 3:15











      • @MichaelHampton Detail added. Thanks.

        – Isaac
        Jan 14 '18 at 3:46






      • 1





        Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

        – Mikko Rantalainen
        Apr 9 '18 at 10:52
















      22














      Doing a:



      $ history -c; history -w


      Will clear history in memory and write that to the HISTFILE file.

      That will clear both memory and file history.



      If it is required that nothing else of the present session would be written to the history, then, unset HISTFILE will prevent any such logging.






      share|improve this answer


























      • And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

        – Michael Hampton
        Jan 14 '18 at 3:15











      • @MichaelHampton Detail added. Thanks.

        – Isaac
        Jan 14 '18 at 3:46






      • 1





        Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

        – Mikko Rantalainen
        Apr 9 '18 at 10:52














      22












      22








      22







      Doing a:



      $ history -c; history -w


      Will clear history in memory and write that to the HISTFILE file.

      That will clear both memory and file history.



      If it is required that nothing else of the present session would be written to the history, then, unset HISTFILE will prevent any such logging.






      share|improve this answer















      Doing a:



      $ history -c; history -w


      Will clear history in memory and write that to the HISTFILE file.

      That will clear both memory and file history.



      If it is required that nothing else of the present session would be written to the history, then, unset HISTFILE will prevent any such logging.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jan 14 '18 at 3:26

























      answered Jan 13 '18 at 15:07









      IsaacIsaac

      11.9k11852




      11.9k11852













      • And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

        – Michael Hampton
        Jan 14 '18 at 3:15











      • @MichaelHampton Detail added. Thanks.

        – Isaac
        Jan 14 '18 at 3:46






      • 1





        Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

        – Mikko Rantalainen
        Apr 9 '18 at 10:52



















      • And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

        – Michael Hampton
        Jan 14 '18 at 3:15











      • @MichaelHampton Detail added. Thanks.

        – Isaac
        Jan 14 '18 at 3:46






      • 1





        Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

        – Mikko Rantalainen
        Apr 9 '18 at 10:52

















      And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

      – Michael Hampton
      Jan 14 '18 at 3:15





      And make sure to unset HISTFILE to ensure nothing else gets written at the end of the session.

      – Michael Hampton
      Jan 14 '18 at 3:15













      @MichaelHampton Detail added. Thanks.

      – Isaac
      Jan 14 '18 at 3:46





      @MichaelHampton Detail added. Thanks.

      – Isaac
      Jan 14 '18 at 3:46




      1




      1





      Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

      – Mikko Rantalainen
      Apr 9 '18 at 10:52





      Editing HISTFILE and doing history -c && history -r would replace your current history with manually modified history. In some cases, that may be better than throwing all the history away.

      – Mikko Rantalainen
      Apr 9 '18 at 10:52













      9














      bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.



      If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.



      Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.






      share|improve this answer



















      • 3





        A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

        – Isaac
        Jan 13 '18 at 15:20


















      9














      bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.



      If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.



      Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.






      share|improve this answer



















      • 3





        A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

        – Isaac
        Jan 13 '18 at 15:20
















      9












      9








      9







      bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.



      If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.



      Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.






      share|improve this answer













      bash has a session history in memory which is written to file if the shell variable HISTFILE is set to a filename when bash exits.



      If you delete the file pointed to by HISTFILE, unset that variable, and exit bash, then that shell session will not leave any persistent history.



      Failing to unset the HISTFILE variable but deleting the file would just empty the persistent history, but the current session's history would be saved when the shell exits.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 13 '18 at 14:10









      KusalanandaKusalananda

      130k17247407




      130k17247407








      • 3





        A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

        – Isaac
        Jan 13 '18 at 15:20
















      • 3





        A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

        – Isaac
        Jan 13 '18 at 15:20










      3




      3





      A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

      – Isaac
      Jan 13 '18 at 15:20







      A history -c; history -w will clear both memory and file history. Unsetting HISTFILE is only required if no further commands should be logged to the history (not exactly what was asked IMhO).

      – Isaac
      Jan 13 '18 at 15:20













      0














      While leaving the shell, do it all in once, like
      echo "" > ~/.bash_history & history -c & exit






      share|improve this answer








      New contributor




      user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























        0














        While leaving the shell, do it all in once, like
        echo "" > ~/.bash_history & history -c & exit






        share|improve this answer








        New contributor




        user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.























          0












          0








          0







          While leaving the shell, do it all in once, like
          echo "" > ~/.bash_history & history -c & exit






          share|improve this answer








          New contributor




          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.










          While leaving the shell, do it all in once, like
          echo "" > ~/.bash_history & history -c & exit







          share|improve this answer








          New contributor




          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 20 mins ago









          user853069user853069

          1




          1




          New contributor




          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          user853069 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.























              -1














              "How can I delete my bash history for real?"



              Exit bash, start a different shell, delete the bash history file.



              or



              logout, log into a different account that has write permission on the history file, delete the history file.






              share|improve this answer




























                -1














                "How can I delete my bash history for real?"



                Exit bash, start a different shell, delete the bash history file.



                or



                logout, log into a different account that has write permission on the history file, delete the history file.






                share|improve this answer


























                  -1












                  -1








                  -1







                  "How can I delete my bash history for real?"



                  Exit bash, start a different shell, delete the bash history file.



                  or



                  logout, log into a different account that has write permission on the history file, delete the history file.






                  share|improve this answer













                  "How can I delete my bash history for real?"



                  Exit bash, start a different shell, delete the bash history file.



                  or



                  logout, log into a different account that has write permission on the history file, delete the history file.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 14 '18 at 2:07









                  useruser

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416820%2fwhy-deleting-bash-history-is-not-enough%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      濃尾地震

                      How to rewrite equation of hyperbola in standard form

                      No ethernet ip address in my vocore2