9951 explained code solutions for 126 technologies


ubuntuHow to print terminal/console history with timestamps


HISTTIMEFORMAT="%F %T " && historyctrl + c
history

prints entire commands history for current user

HISTTIMEFORMAT

set format for command time to print

%F %T

e.g. 2022-02-02 16:47:53


Usage example

HISTTIMEFORMAT="%F %T " && history
output
 2000  2022-02-02 16:47:53 history --help
 2001  2022-02-02 16:49:03 history | tail -n 10
 2002  2022-02-02 16:51:45 history | grep "git"
 2003  2022-02-02 16:52:56 HISTTIMEFORMAT="%F %T " && history