Linux Command History – Add Time and Date Stamps
Ever want to know the time and date you executed a specific command on your Linux server? If you’re like me and constantly using your Linux command history in your bash shell this little addition to your .bash_profile comes in very handy.
Append these directives to you .bash_profile in your user directory:
HISTSIZE=10000
HISTFILESIZE=”
HISTCONTROL=ignoreboth
HISTTIMEFORMAT=’%a, %d %b %Y %l:%M:%S%p %z ‘
In this case a very large history will be kept, 10,000 commands to be exact. The output from a history command will look like this:
84 Fri, 13 Nov 2009 9:50:10AM -0500 history
85 Fri, 13 Nov 2009 9:57:16AM -0500 locate .bash_profile
86 Fri, 13 Nov 2009 9:57:38AM -0500 cat .bash_profile
87 Fri, 13 Nov 2009 9:58:50AM -0500 history
To have the changes to your .bash_profile take effect do one of the following:
- # . .bash_profile
- # source .bash_profile
- or thirdly log out and back in
I like the valuable information you provide in your articles. I will bookmark your weblog and check again here frequently. I am quite sure I will learn a lot of new stuff right here! Best of luck for the next!