User Tools

Site Tools


bash:history

BASH - History

history is used to keep track of all commands that were executed on a Linux machine.

By default, the history command stores the last one thousand commands.


History

history

returns:

    1  vi .config/beets/config.yaml 
    2  beet ls
    3  beet remove
    4  beet import /home/peter/Music
    5  beet ls
    6  vi .config/beets/config.yaml 
    7  beet ls
    8  beet import /home/peter/Music
    9  beet ls
   10  vi .config/beets/config.yaml 
   11  beet import /home/peter/Music
...

As can be seen the timestamp is not in the output.


Add timestamp to history

export HISTTIMEFORMAT="%F %T "
  • %F: shows Date in the format ‘YYYY-M-D’ (Year-Month-Day)
  • %T: shows Time in the format ‘HH:MM:S’ (Hour:Minute:Seconds)

History

history

returns:

    1  2019-12-23 13:02:38 vi .config/beets/config.yaml 
    2  2019-12-23 13:02:38 beet ls
    3  2019-12-23 13:02:38 beet remove
    4  2019-12-23 13:02:38 beet import /home/peter/Music
    5  2019-12-23 13:02:38 beet ls
    6  2019-12-23 13:02:38 vi .config/beets/config.yaml 
    7  2019-12-23 13:02:38 beet ls
    8  2019-12-23 13:02:38 beet import /home/peter/Music
    9  2019-12-23 13:02:38 beet ls
   10  2019-12-23 13:02:38 vi .config/beets/config.yaml 
   11  2019-12-23 13:02:38 beet import /home/peter/Music
...

Make “HISTTIMEFORMAT” variable persistent across reboots

Add this line to the .bashrc file.

~/.bashrc
...
export HISTTIMEFORMAT="%F %T "
...

and enable this change:

source  ~/.bashrc

If you want to enable timestamp in history command for all local users too, then define the variable HISTTIMEFORMAT in /etc/profile file instead of root user’s ~/.bashrc file.

bash/history.txt · Last modified: 2021/01/26 16:24 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki