Display date and time for commands executed in linux

We can always set time to the commands showed in history command. Why we require to set time for this?

This is totally a security measure and used for troubleshooting/fingerprinting a security threat.

history command sample output before setting this variable.

 466  df -h
 467  df 
 468  exit
 469  nfsstat 
 470  find / -iname *.ppt
 471  ftp2
 472  man ping
 473  ping -R google.com

So how to set that?

Use inbuilt variable HISTTIMEFORMAT to set the values as shown below


%F for setting year/month/day

%T for setting time

now try to execute history command to see the difference


sample output

500  2011-03-16 17:06:09 exit
 501  2011-03-16 17:06:14 apt-get install tree
 502  2011-03-16 17:06:36 tree 
 503  2011-03-16 17:06:54 man tree
 504  2011-03-16 17:07:02 tree -d
 505  2011-03-16 17:07:07 tree 

If you restart/logout from machine will this setting available to you?

A simple answer for this is no. Then how can we make it permanent?

Just append this variable to .bash_profile for every user.

echo "export HISTTIMEFORMAT='%F %T '" >> ~/.bash_profile

How about setting this value to the new user which are going to be created on the machine?

export it to /etc/profile file

echo "export HISTTIMEFORMAT='%F %T '" >> /etc/profile

Please feel free to comment your thoughts on this.

Show your love by sharing this..!
Share on VKShare on StumbleUponShare on YummlyPrint this pageFlattr the authorShare on TumblrEmail this to someoneBuffer this pageShare on Google+Share on LinkedInShare on FacebookTweet about this on TwitterPin on PinterestShare on RedditDigg this
The following two tabs change content below.
My name is Surendra Kumar Anne. I hail from Vijayawada which is capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. I work with ICE systems, Sydney as Sr. Consultant. You can contact me at surendra (@) linuxnix dot com.
  • Jesus Escudero


  • Wshum80

    Can you still;
    Repeat of that.

  • Pingback: Change shell properties with Linux shopt command()

  • Pingback: Change shell properties with Linux shopt command()

  • Jassim Shaikh

    Very useful site….explained in such a simple way even a linux fresher can become expert…grt going guys

    • http://www.linuxnix.com Surendra

      thanks Shaikh, Keep visiting the site and refer your friends to http://www.linuxnix.com

  • Ashok Kumar

    Its very dangerous command because its showing only current date for all history.

    • BotelhoPinto

      That’s the problem.

  • yrak

    yes, I also notice it..my history only shows the current date and not the date where the command executed.
    how will i display it??can someone help me…Thanks :)