Get time taken to execute task in Ubuntu

To check and get a detailed response on how long a task took on your Ubuntu server you can use the time utility. Note that this is not the inbuilt time function.

Installing time can be done with:

sudo apt-get install time

Now you can time your script executions with

/usr/bin/time -v [TASKHERE]

Example to get size of the var directory

/usr/bin/time -v du -sh /var

returns

1.2G    /var
        Command being timed: "du -sh /var"
        User time (seconds): 0.01
        System time (seconds): 0.06
        Percent of CPU this job got: 26%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.31
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 3000
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 387
        Voluntary context switches: 8227
        Involuntary context switches: 3
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

Giving you many types of timings for the task.