Command history timestamps

Nod

Honorary Master
Joined
Jul 22, 2005
Messages
10,968
Reaction score
2,715
Location
Darling
Ever tried to find out what people did on the server?
Have you found the offending command, but do not know when it was done?

Set the following environment variable:
Code:
export HISTTIMEFORMAT='%F %T - '
When you execute `history`, the output will will now look like:
Code:
1072  2013-03-25 12:18:09 - ls -ltr
 1073  2013-03-25 12:18:18 - cd <dir>
 1074  2013-03-25 12:18:19 - ls -ltr
 1075  2013-03-25 12:36:38 - cd
 1076  2013-03-25 12:36:41 - cd temp
 1077  2013-03-25 12:36:42 - ls
 1078  2013-03-25 12:36:51 - mkdir <dir>
 1079  2013-03-25 12:36:56 - mv <file>.tar.gz <dir>/
 1080  2013-03-25 12:36:58 - cd <dir>
 1081  2013-03-25 12:37:00 - alias
 1082  2013-03-25 12:37:10 - history|grep ftp
 1083  2013-03-25 12:37:54 - ftp ftp://ftpserver
 1084  2013-03-25 14:25:53 - echo <something>
 1085  2013-03-25 14:42:49 - history
 
Time stamps are useful, but if you are not worried about the time you can just type:

# cat .bash_history

Never knew about the history command. I see when I type it the time stamps are there.
 
Time stamps are useful, but if you are not worried about the time you can just type:

# cat .bash_history

Never knew about the history command. I see when I type it the time stamps are there.

There are many ways to skin a cat.
The number in front of the output from the history command, can also be used to repeat the command by type a "!" infront the the number, for example:
Code:
!1083
This will repeat the ftp command from the output above.
 
Top
Sign up to the MyBroadband newsletter
X