Want to add a timestamp (date and time) next to each command from your Bash history? This can be done by using the
HISTTIMEFORMAT
Bash variable.Bash keeps a history of the commands you type, which can be accessed by typing
history
. By default you see a number followed by the commands you've used recently:$ history
1889 cd Cloaker/
1890 ./Cloaker.run
1891 sudo apt upgrade
1892 sudo apt autoremove
1893 history
With the help of the
HISTTIMEFORMAT
Bash variable you can show the date and time when each command was executed. This can be useful in various occasions, including to remember which commands you ran in a specific time-frame, to undo various operations, and so on. It's worth noting that if this variable is set, the time stamps are written to the history file, so they are preserved across shell sessions. So the first time you enable it, you won't see the correct date and time for your previously used commands.
0 Comments