How to do it...

  1. The time command measures an application's execution time.

Consider the following example:

        $ time APPLICATION

The time command executes APPLICATION. When APPLICATION is complete, the time command reports the real, system, and user time statistics to stderr and sends the APPLICATION's normal output to stdout.

        $ time ls
        test.txt
        next.txt
        real    0m0.008s
        user    0m0.001s
        sys     0m0.003s
An executable binary of the time command is found in /usr/bin/time. If you are running bash, you'll get the shell built-in time by default. The shell built-in time has limited options. Use an absolute path (/usr/bin/time) to access the extended functionality.
  1. The -o option will write the time statistics to a file:
        $ /usr/bin/time -o output.txt ...

Get Linux Shell Scripting Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.