Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Security
User Name
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.


  Search this Thread
Old 05-29-2008, 11:59 AM   #1
Senior Member
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,419

Rep: Reputation: 55
How can I append the date/time stamp to commands in history?

How can I append the date/time stamp to commands in history?

Like this guy did:
[root~]# history | grep audit
240 2008-04-25 03:53:32 PM cat logs/initialaudit.log
243 2008-04-25 03:53:32 PM rm -f initialaudit
244 2008-04-25 03:53:32 PM rm -f initialaudit.1
247 2008-04-25 03:53:32 PM ./initialaudit
252 2008-04-25 03:53:32 PM cat initialaudit.log
273 2008-04-22 02:14:20 PM cat initialaudit.log
275 2008-04-22 02:16:55 PM cat initialaudit.log-1208841284
826 2008-04-24 07:25:12 PM history | grep audit
848 2008-04-24 10:12:14 PM history | grep audit
857 2008-04-24 10:15:50 PM vi initialaudit
867 2008-04-25 03:28:04 PM history | grep audit
871 2008-04-25 03:53:40 PM history | grep audit
Old 05-29-2008, 12:17 PM   #2
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
I didn't know myself, but the bash man page turns up the HISTTIMEFORMAT environment variable. A quick google later and :
gets the job done. I learn something new every day
Old 05-29-2008, 12:21 PM   #3
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
In bash 3.0 and newer you can define an environment variable called HISTTIMEFORMAT and put its value to a time format, using the time specification of the command date. Once you have defined this variable (you can put the definition in your ~/.bashrc) the history will be timestamped. For example
export HISTTIMEFORMAT="%Y%m%d %H:%M:%S "


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic date stamp in text document gemini728 Linux - Newbie 3 02-25-2009 11:15 AM
date stamp file or directory name dgermann Linux - General 6 02-02-2008 05:53 PM
Rename file based on its own date/time stamp airman99 Linux - General 19 09-05-2006 08:52 AM
Rename file with date stamp MacSob Linux - General 6 09-13-2005 02:30 PM
Time stamp in Samba is 11 hours behind time stamp in Linux Linh Linux - General 3 09-04-2003 01:44 PM > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration