Ubuntu – How to see time stamps in bash history

bashcommand lineenvironment-variableshistorytimestamp

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

Best Answer

  • 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.