How to Display the Timestamp in Your Bash History

John John (304)
2 minutes

It's nice to have quick access to your command history on the command line, but sometimes it's valuable to know exactly when you typed a command. This guide will show you how to customize the output of the history command.

Posted in these interests:
h/bash5 guides
h/linux41 guides
h/sysadmin12 guides

Right from the command line you can set the HISTTIMEFORMAT variable that determines the format of your history.

To set this variable simply type:


Now check your history:


You should see an output like this:

 2027  20/08/15 14:32:05 top -u
 2028  20/08/15 14:32:16 ps -ax|grep goats
 2029  20/08/15 14:32:17 uptime
 2030  20/08/15 14:32:22 HISTTIMEFORMAT="%d/%m/%y %T "
 2031  20/08/15 14:32:24 history

You can set this variable in your .bashrc file so that it takes effect during every shell session.

Open .bashrc to edit:

vim ~/.bashrc

And add the following:

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

Now save, quit, and source this file:

source ~/.bashrc

Here's a bit more on HISTTIMEFORMAT from documentation: If this variable is set and not null, its value is used as a format string for strftime to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions. This uses the history comment character to distinguish timestamps from other history lines.

Why pay just to find out a vehicle's history?
John John (304)
1 minute

Before you buy a car, truck, or SUV, you will definitely want to get a vehicle history report.