Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Command History
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Jarli
n00b
n00b


Joined: 22 Mar 2012
Posts: 8

PostPosted: Wed Nov 14, 2012 3:54 pm    Post subject: Command History Reply with quote

Is there anyway to determine when a command was run on Gentoo, through a terminal session?

I know the 'history' command shows the list of commands, but I would like to see if there is a time stamp.
Back to top
View user's profile Send private message
eccerr0r
Advocate
Advocate


Joined: 01 Jul 2004
Posts: 3939
Location: USA

PostPosted: Wed Nov 14, 2012 4:43 pm    Post subject: Reply with quote

This link got me

http: //larsmichelsen.com/open-source/bash-timestamp-in-bash-history/

This assumes that you're using bash.
_________________
Intel Core i7 2700K@ 4.1GHz/HD3000 graphics/8GB DDR3/180GB SSD
What am I supposed to be advocating?
Back to top
View user's profile Send private message
tomk
Administrator
Administrator


Joined: 23 Sep 2003
Posts: 7219
Location: Sat in front of my computer

PostPosted: Wed Nov 14, 2012 4:50 pm    Post subject: Reply with quote

Moved from Gentoo Chat to Portage & Programming as it's not about Gentoo itself.

As the link that eccerr0r posted shows you need to set HISTTIMEFORMAT, assuming you're using bash. Obviously this will only show you the timestamp after you've set it, for commands before that it will just use the current time which is then cached.
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
khayyam
Advocate
Advocate


Joined: 07 Jun 2012
Posts: 2244

PostPosted: Wed Nov 14, 2012 7:10 pm    Post subject: Reply with quote

Jarli ...

zsh timestamps (with 'shopt extended_history' set) ... the history file can then be parsed with the following:

Code:
# perl -lne 'm#: (\d+):\d+;(.+)# && printf "%s :: %s\n",scalar localtime $1,$2' $HISTFILE

I'm not sure if bash timestamps are constructed in a similar manner but is should be parsable none the less with a similar oneliner.

best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum