I want to record bash execute history in a log, including input and output, and timestamp.
The command history
only can record input, but not output and timestamp.
What can I do to archive this?
Asked
Active
Viewed 313 times
0

He Yuntao
- 86
- 11
-
Not easy (not that I heard of, actually). A compromise is to record everything as printed on screen, which is usually done on the terminal emulator level. You don't have timestamps that way, but you can include timestamps in your prompt to guide you, which is what I do. – 4ae1e1 Nov 03 '15 at 06:16
-
By the way, Zsh's history at least has the advantage of including timestamps. – 4ae1e1 Nov 03 '15 at 06:17
-
Possible duplicate of [Print execution time of a shell command](http://stackoverflow.com/questions/1656425/print-execution-time-of-a-shell-command) – Zsolt Botykai Nov 03 '15 at 09:43
-
@ZsoltBotykai I think it's two problems, I don't want execute-time, i want a timestamp, it just like '2015-11-03 17:53:29' – He Yuntao Nov 03 '15 at 09:52
-
Somebody might flood the log by constantly typing `cat output.log` – hek2mgl Nov 03 '15 at 10:08
1 Answers
1
Without the proper time-stamp you could use the infamous script
command, which allows the recording of a terminal session to a file. Now you can use its' -t
parameter to record the time between two commands (but this will be recorded to STDERR
(read the fine manual). Then you have the option to (altogether with script
) to either set your $PS1
to include a time-stamp (or $PROMPT_COMMAND
), so that was that is also included in script
's output.

Zsolt Botykai
- 50,406
- 14
- 85
- 110