On Linux, a history of recent console commands is stored in the .bash_history file. You can view the contents of this file with any text editor or with the command:
$ history
The command will output a numbered list of all the commands you have previously run. For convenience, you can add the timestamp (date and time) of the command execution to the bash history.
To do this, you need to add the following parameters to the ~/.bashrc file.
$ mcedit $HOME/.bashrc
export HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S '
Or use:
$ echo 'export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "' >> ~/.bash_profile
Additionally, you can increase the size of the .bash_history file to 2000 lines:
export HISTSIZE=2000
A list of commands that do not need to be saved to the bash history can be added to the histignore list:
export HISTIGNORE="ls:ll:history:w:htop"
To apply the changes, you need to re-login or run the command:
$ source ~/.bashrc
The date and time will now be displayed opposite the command in the bash history.