I want to get the total time a program was run daily for personal logging (from start to close even if it is in the background). For example: Firefox.

  • Is there a system log that keeps track of open and close times?
  • Is there a pre-built utility that can be used?

And, if none, some pointers for writing a script?

  • 1
    time or usr/bin/time ? – 123 Jan 12 '16 at 14:48

The accounting utilities (e.g. GNU's implementation) track user activity and provide a number of tools to report on it; for example,


will list the last commands executed, and


(run as root) will provide an activity summary.

To show the amount of time a given process ran, do something like

sudo sa | grep chromium

This will output a number of values:

   5    6781.67re       3.78cp         0avio    265418k   chromium
   4    4521.35re       0.00cp         0avio    176024k   chromium*

The first column is the number of times the given process ran, the second is the number of minutes the processes ran in total (which may be simultaneous). The line ending with * summarises processes which forked without executing another binary. Since browsers tend to execute multiple processes simultaneously, the starred instance represents the extra processes used; you can get an idea of the real time spent by subtracting the values in this case.

These values are aggregated over all users, so they're only really usable for your purpose if you're the only user on your system.


I ended up using the following script to launch the program and replaced it with the default pointer to the application.

echo -n "$(date +%s)" >> ~/myapplog.log
echo ",$(date +%s)" >> ~/myapplog.log

It basically logs the start and stop times of the application in form of timestamp for each session in a new line separated by a comma. eg: 1452663495,1452663502

You can change (date +%S) to the format of your liking (see man page for date)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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