When examining the history command output I find it useful to have the date and time of when the command was executed so in my ~/.bashrc file I have:
export HISTTIMEFORMAT='%F %R '
Which provides output like:
$ history
1 2014-03-05 21:38 cd /etc
2 2014-03-05 21:38 ls
3 2014-03-05 21:38 ps -aux
4 2014-03-05 21:38 history
The default history file output as well as cache output is 500 lines I tend to increase this by double since I don’t like to lose my early history. Add this to your ~/.bashrc file:
export HISTSIZE=1000
export HISTFILESIZE=1000
*Note HISTSIZE controls the amount during the active session and HISTFILESIZE controls the size of the saved history file
Another annoying thing in your history file output can be duplication of commands in succession, to prevent these unnecessary duplicates I add the following to my ~/.bashrc file:
export HISTCONTROL=ignoredups
Sometimes you accidentally get ahead of yourself and mean to type sudo su – but instead enter your password at the prompt which then gets stored in your history cache. When this happens you can do the following command to remove that particular line in the history output.
$ history -d #
* Note where the # is the line number correlating to what you want to delete.
Other times you want to clear all your history for a particular shell session which you can do with the command:
$ history -c
If you want to get rid of all history permanently even from past sessions you can do the following:
$ :> ~/.bash_history
$ history -c
Hoping this post will help you to maintain the commands history.. Happy Learning !!
https://www.facebook.com/datastage4you
https://twitter.com/datagenx
No comments:
Post a Comment