Shell Programming Blog Shell Programming Blog

Sunday, 14 October 2012

Linux Bash Scripting: How to ignore specific commands from being stored in the history in Linux

Unknown | 19:39 | |


Bash Linux Unix shell scripting

If you see the history of your commands using the "history" command, you can see all the commands that you executed in the command line. If you don't want certain basic commands to be stored in your history, you can ignore them using HISTIGNORE. You can specify all the commands that you want to ignore in the HISTIGNORE. 

In the below code, I have ignored the commands pwd, ls, ls -ltr and l using HISTIGNORE. Then I am executing some commands in the command line. Finally I'm checking the output of the history command.


[Note that history did not record ls, l, ls -ltr and pwd]

Please note that adding ls does not exclude the command ls -al from being included in the history. So, you need to specify the complete command to make it as an exception.

3 comments:

  1. This will be useful for the new system admins to avoid being caught for executing few commands.

    ReplyDelete
  2. You can also set the bash environment variable HISTCONTROL to any of "ignorespace", "ignoredups" or "ignoreboth".

    Ignorespace will cause any command line beginning with a space to not be placed in the history file. So if you were buzzing along, and suddenly needed some help with the sudo command, instead of typing "man sudo", you could type " man sudo", and it wouldn't show up in your history file. (contrived case...)

    Ignoredups will cause any command repeated twice in a row to only appear in the history file once, so that running back through the history won't show the 5 pwd's you did.

    Ignoreboth will cause both of the above to be in effect.

    Using HISTIGNORE combined with ignorespace will allow you to have a huge amount of control over what appears in your history file.

    ReplyDelete
    Replies
    1. @Robert Nix Thanks for your valuable points.. Your information will help more people..

      Delete

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
3. Please do not spam, spam comments will be deleted immediately upon my review.

Regards,
Mohamed Abubakar Sittik A

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming