Linux Command History with date and time
Solution 1:
Regarding this link you can make the first solution provided by krzyk permanent by executing:
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
source ~/.bash_profile
Solution 2:
Try this:
> HISTTIMEFORMAT="%d/%m/%y %T "
> history
You can adjust the format to your liking, of course.
Solution 3:
In case you are using zsh you can use for example the -E
or -i
switch:
history -E
If you do a man zshoptions
or man zshbuiltins
you can find out more information about these switches as well as other info related to history:
Also when listing,
-d prints timestamps for each event
-f prints full time-date stamps in the US `MM/DD/YY hh:mm' format
-E prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
-i prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
-t fmt prints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions described for the %D{string} prompt format in the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1). The resulting formatted string must be no more than 256 characters or will not be printed
-D prints elapsed times; may be combined with one of the options above
Solution 4:
It depends on the shell (and its configuration) in standard bash only the command is stored without the date and time (check .bash_history
if there is any timestamp there).
To have bash store the timestamp you need to set HISTTIMEFORMAT
before executing the commands, e.g. in .bashrc
or .bash_profile
. This will cause bash to store the timestamps in .bash_history
(see the entries starting with #
).