How to make our command history not remember certain commands

We all know what the Bash history. Many times we need for some reason (security, paranoia, etc.) that a certain command is NOT saved in the history, that is, and for example, we want all commands to be saved except those related to ssh, in this way if someone manages to access our computer will not be able to know to which computer we do SSH.

To exclude everything related to the command ssh we write the following line in .bashrc :

HISTIGNORE='ere*:ssh*'

In this way if for example we do something like:

ssh root@virtue

... will not have been saved in the history 😉

If we want it to exclude everything related to the command ls we write the following:

HISTIGNORE='ere*:ls*'

Remember that the file .bashrc has a period at the beginning of the name, which means that it is a hidden file that is in our home. If you wish, using the echo command you can write directly in .bashrc without having to open it, for example, let's exclude everything related to ssh from the history:

echo "HISTIGNORE='ere*:ssh*'" >> $HOME/.bashrc

Well I think there is nothing more to add.

regards


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.   q0 said

    This almost inspires me to open a man page and post on this site, writing about how to list hidden files should be a huge contribution.

  2.   José Torres said

    Interesting tool. The ere it represents?

  3.   truko22 said

    Interesting 😀 to the bookmarks without in the future I need it, thank you very much.

  4.   himekisan said

    Really interesting and useful, especially for those of us in the world of network administration (paranoia never hurts).

  5.   dhunter said

    And there is the pragmatic mode, just type a space before the command and that's it, it won't be remembered.

    1.    Percaff_TI99 said

      Well, I always use history -c, but there is nothing left xD, that option is very simple and selective.

    2.    cookie said

      The space thing didn't work for me.

      1.    KZKG ^ Gaara said

        Neither do I, that's why I didn't put it in the post from the beginning 🙁

        1.    xpt said

          adding:
          HISTCONTROL = ignorespace
          the space works 🙂

        2.    rainerhg said

          The space thing has worked for me for months configuring this way:
          HISTIGNORE = '(space) + (*)' => like this: HISTIGNORE = '*'
          😉

  6.   cookie said

    Interesting Gaara. Although I don't need it at the moment, I like to know that I have a whole repository of tips here at DesdeLinux.

  7.   Lenin Ali said

    Short, concise and useful! excellent contribution.