|
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.
This will be useful for the new system admins to avoid being caught for executing few commands.
ReplyDeleteYou can also set the bash environment variable HISTCONTROL to any of "ignorespace", "ignoredups" or "ignoreboth".
ReplyDeleteIgnorespace 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.
@Robert Nix Thanks for your valuable points.. Your information will help more people..
Delete