Display date & time in Linux history command

One nifty tip to enable timestamps in the history command in Linux.

When you enter the history command on a Linux server or macOS terminal, you only see the list of commands but not the date &/or time when those commands were executed. It looks similar to this.

That is why I use this simple but very useful tip to display the timestamps against all the commands in the output of the history command. Below is how to enable it.

  • Open .bash_profile or /etc/profile file (read the note below).

Edit /etc/profile file to enable the timestamps for all the users. If you want to enable it for a particular user, then edit .bash_profile file of that user.

  • Add the below line.

%d — date

%m — month

%y — year

%T — time (in hh:mm:ss format)

  • Source the file. You can also log out & log back in to reflect the changes.

If you type history command now, it will neatly display the timestamps against each command.

Even though it looks trivial, it is one of the very first things that I do on a newly created Linux server.

If you like this post, please share it with your friends. I mostly write about DevOps & Linux & am looking forward to posting more.

DevOps Architect, Music/Book/Photography/Fitness lover & Blogger