When using the history command , is it possible to get more details such as timestamp of each result? [duplicate]

Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?

Bottom-Line: Execution time in the Bash history


Solution 1:

Press Ctrl+Alt+T to open a terminal, then run one of the commands below:

HISTTIMEFORMAT="%d/%m/%y %T "  # for e.g. “29/02/99 23:59:59”
HISTTIMEFORMAT="%F %T "        # for e.g. “1999-02-29 23:59:59”

To make the change permanent for the current user run:

echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc  # or respectively
echo 'HISTTIMEFORMAT="%F %T "' >> ~/.bashrc
source ~/.bashrc

To test the effects run:

history

For more info see man bash or An A-Z Index of the Bash command line for Linux.

For commands that were run before HISTTIMEFORMAT was set, the current time will be saved as the timestamp. Commands run after HISTTIMEFORMAT was set will have the proper timestamp saved.

Solution 2:

Open terminalCtrl+Alt+T and run,

HISTTIMEFORMAT="%d/%m/%y %T "

then,

history

To make the changes permanent follow the below steps,

gedit ~/.bashrc

you need to add the below line to .bashrc file and then save it,

export HISTTIMEFORMAT="%d/%m/%y %T "

run the below command to source .bashrc file,

source ~/.bashrc

After that run history command.

enter image description here

source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/

Solution 3:

Yes, you can: if you set $HISTTIMEFORMAT, the .bash-history will be properly timestamped. That doesn't help with existing .bash-history content, but will help in the future.

Solution 4:

Changing HISTIMEFORMAT didn't work for me, because I'm using zsh.

If you want to make it work with zsh, you just have to type : history -i

Solution 5:

You 'll see changes on next login.

echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc