Adding Date And Time To Your Bash History

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Submitted by linuxscooter (Contact Author) (Forums) on Thu, 2009-05-07 11:11. :: Linux

Adding Date And Time To Your Bash History

This is a quick but handy addon (RedHat/CentOS) to enhance your bash history (bash > 3.0).

It comes in handy particularly if there are multiple people maintaining a given server (so you can see when a command was performed) or even if you are the sole maintainer, but can't remember exactly when you did or changed something.

Edit your /etc/bashrc and append to the bottom:

export HISTTIMEFORMAT="%h/%d - %H:%M:%S "

From next login instead of:

574  tail -f /var/log/maillog
575  mailq | tail -15
576  tail -f /var/log/maillog
577  less /var/log/maillog

you get:

1002  Apr/30 - 11:46:16 grep duncan /var/log/maillog
1003  Apr/30 - 14:17:40 passwd jduncan
1004  Apr/30 - 14:18:02 smbpasswd jduncan
1005  Apr/30 - 14:50:28 history 10

Hope this helps someone;)


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Tue, 2009-05-26 12:00.

Well thank you very much, just a little nifty thing I wasn't looking for but am glad to find!!!

 

 

Submitted by jon (registered user) on Sun, 2009-05-10 06:17.
Excellent tip, thanks!
Submitted by TeigneuX (not registered) on Thu, 2009-05-07 16:04.
I prefer snoopy package which writes on syslog all commands Because the .bash_history can be erased by the system
Submitted by Joao Baptista (not registered) on Thu, 2009-05-07 12:19.

To make it global and permanent to all users, edit /etc/profile and append to the bottom.

 

Submitted by thirupathy (not registered) on Thu, 2009-10-29 19:36.

HI

For me this is not working in Redhat RHEL 3 version . Though i edited the file in /etc/profile

export HISTTIMEFORMAT="%h/%d - %H:%M:%S "
Submitted by ginocic (registered user) on Thu, 2009-05-07 11:20.
It works also in my Ubuntu box. The file to modify is $HOME/.bashrc
Submitted by ginocic (registered user) on Thu, 2009-05-07 10:31.

Yes, I think your tip could be a great help. Thank a lot for this :)

Keep up the great work!!!!

Submitted by Ojee2 (not registered) on Thu, 2009-05-07 09:28.

Very nice!

Works on Ubuntu/Debian too!

Sponsored Links: Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com

One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com

One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com

AT&T Synaptic Compute as a Service. Boost your power on demand.

Trial: IBM Cognos Express Reporting, Analysis & Planning