Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?

Bottom-Line: Execution time in the Bash history

share|improve this question
    
Possible duplicate of How to know the time of execution of previous commands – Paranoid Panda Jan 12 at 17:53
up vote 57 down vote accepted

Try this, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

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

or

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile ; source ~/.bash_profile

Then

history

For more info see man bash or An A-Z Index of the Bash command line for Linux.

share|improve this answer
1  
Thank you for answering , just added bash to apply the changes. – Raja Dec 15 '13 at 12:06
2  
Thanks for the correction :) – Mitch Dec 15 '13 at 12:06
1  
@Raja: Your method to reload bash opens a shell into the shell ;-) and this can cause a "A process is running..." message when closing the terminal. Isn't better to reload the edited file? – Helio May 21 '15 at 9:45
1  
In history file, it seems timestamp is not stored, thus when print timestamp: 1. for command in shell itself, since timestamp is remembered in memory, it will be print correctly. 2. for command in history file, it seems to use the timestamp when the file is last modified. – Eric Wang Oct 13 '15 at 4:45
2  
For Americans its HISTTIMEFORMAT="%m/%d/%y %T " :) – Jamil Nov 6 '15 at 16:04

Open terminalCtrl+Alt+T and run,

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

then,

history

To make the changes permanent follow the below steps,

gedit ~/.bashrc

you need to add the below line to .bashrc file and then save it,

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

run the below command to source .bashrc file,

source ~/.bashrc

After that run history command.

enter image description here

source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/

share|improve this answer
    
Thanks for answering , \will it be permanent change ? – Raja Dec 15 '13 at 12:06
    
Hey, I'm doing this in OS X and Windows (through MINGW), and I'm adding it into .bash_profile, what's the diff between profile and rc? – Adrián Salgado Oct 1 '15 at 17:28

Yes, you can: if you set $HISTTIMEFORMAT, the .bash-history will be properly timestamped. That doesn't help with existing .bash-history content, but will help in the future.

share|improve this answer
1  
can you expand it for more clarity ? – Raja Dec 15 '13 at 12:06
1  
@Raja I think it means that for the already existing history the time stamps will not be correct, am I right? – Vesnog Jan 8 '15 at 16:50
    
Correction to previous post: Setting HISTTIMEFORMAT enables the display of the timestamps...even existing. My favorite is:HISTTIMEFORMAT='%F %T ' as it matters not from which country you reside...everyone knows immediately what time it is. :) – user491029 Jan 8 at 22:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.