LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
Search this Thread
Old 05-29-2008, 10:59 AM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,257

Rep: Reputation: 53
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, 11:17 AM   #2
beadyallen
Member
 
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 :
Code:
HISTTIMEFORMAT="%c # "
history
gets the job done. I learn something new every day
 
Old 05-29-2008, 11:21 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,492

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
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
Code:
export HISTTIMEFORMAT="%Y%m%d %H:%M:%S "
 
  


Reply


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 10:15 AM
date stamp file or directory name dgermann Linux - General 6 02-02-2008 04:53 PM
Rename file based on its own date/time stamp airman99 Linux - General 19 09-05-2006 07:52 AM
Rename file with date stamp MacSob Linux - General 6 09-13-2005 01:30 PM
Time stamp in Samba is 11 hours behind time stamp in Linux Linh Linux - General 3 09-04-2003 12:44 PM


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

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