Execute command after every command in bash

Viewed 9284

I want to print the date after every bash command I run.

This could help me understand how much a command took to execute when I am away from keyboard.

I know I could do

`DATE=`date +%d/%m/%Y\ %H:%M:%S` && echo $DATE`

to get the date but I don't know how or even if it could be possible to run this command after every command I execute on bash.

I would also be interested in running the same command before every command so I could know how long a command took.

Is it possible?

What file should I edit?

For example:

$ wget google.com
15/07/2017 23:40:05

I would be happy, if I could also introduce this following feauture:

$ wget google.com
15/07/2017 23:40:05 15/07/2017 23:40:11 
Program run for 00:00:06

where the first date is when I ran the program, second is when program terminated the third is self-explanatonary.

As you understood, I don't want to type every time

$ wget google.com && `DATE=`date +%d/%m/%Y\ %H:%M:%S` && echo $DATE`
4 Answers
Related