How to clear command history in Linux

.

history -c

… That simple 😀 LOL !!!

Nothing, is that I always start my posts giving a detailed explanation of the problem, to conclude with the solution, I thought about maybe changing a little 😀

On more than one occasion we have surely wanted to delete the history of commands that we have executed on our computer, for this I previously deleted the file .bash_history located in our home, but it is always better to use the tools or options that the system itself gives us ^ - ^

That is why I find the startup command perfect, a simple parameter (-c) tells the system to clear the command history.

Another method that should work too is:

echo "" > ~/.bash_history

This should put a blank line in our history deleting everything else :)

Well nothing, another tip that I hope you find interesting.

regards


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

17 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   helena_ryuu said

    LoL a super-useful and direct entry, thanks for the advice ^^

    1.    KZKG ^ Gaara said

      Thank you
      I've been a little busy and a little unwilling to write these days, let's see if I write some things today and tomorrow ^ - ^

  2.   Citux said

    The second option had not occurred to me, interesting KZKG ^ Gaara 🙂

    1.    KZKG ^ Gaara said

      It occurred to me in fact writing the post HAHAHAHA, actually I deleted the .bash_history and already HAHAHA

      1.    Hugo said

        You could still have done this:

        cat /dev/null > ~/.bash_history

        Or playing around a bit, maybe this:

        rm ~/.bash_history && touch ~/.bash_history

        In any case, I prefer to use history -d to specifically delete the things that annoy me, or to edit the file, close and start the session again.

  3.   Elynx said

    Simple but useful!

    Thanks!

    1.    KZKG ^ Gaara said

      Thanks to you for commenting ^ - ^

  4.   st0rmt4il said

    And deleting the content of the file with nano or vi and logging in again would not solve the problem?

  5.   Emissary said

    Thank you here I found what I needed.
    A greeting….

  6.   Clandestine said

    Excellent material. The time and dedication given is appreciated.

  7.   Daniel PZ said

    Thank you very much, right to the point!

  8.   Saints said

    Hello mate! Great your contribution, but I would make a small correction:

    the complete command would be: echo ""> ~ / .bash_history && history -c

    The problem is that the command "history -c" only clears the commands used in the open terminal, and on the other hand, when you do the "echo"> ~ / .bash_history "it cleans the file, but leaves you the last one written line, in this case, the clean command itself.

    Therefore, the sum of both with && and in this order, allows you to leave what you want exactly, which is to clear the history of all terminal sessions (including the last one open)

    I hope my contribution is helpful.

  9.   Bartali said

    Hey.
    Thanks for the command, but wouldn't it be more effective to use a secure erase (overwrite) to prevent the erased data from being recovered by third parties?

    A greeting.

    1.    Joseph said

      My dear Bartali, it all depends on what you hide. A simple erase is enough since the history of the terminal rarely contains sensitive data. Secure erase consumes additional resources and power. I use it only in the case of strictly private things or that could be used by cybercriminals.

  10.   José said

    I opened the file '/root/.bash_history' with the editor as 'root', and I deleted the content.

  11.   Anonymous said

    sollocpongan history -c

  12.   AndresD said

    good, none of the mentioned commands work for me.
    the history -c if you clear the history, but when starting the terminal again, it loads everything.
    someone knows how to delete the history permanently. ?
    Thank you