<http://schema.org/articleBody>
"&amp;lt;h3&amp;gt;Introduction&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;The time command is one of the lesser known Linux commands but it can be used to shown how long a command takes to run.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;This is useful if you are a developer and you want to test the performance of your program or script.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;This guide will list the main switches that you will use with the time command along with their meanings.&amp;lt;/p&amp;gt;&amp;lt;h3&amp;gt;How To Use The Time Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;The syntax of the time command is as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time &amp;amp;lt;command&amp;amp;gt; &amp;amp;lt;command switches&amp;amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;For example you can run &amp;lt;a href=&amp;quot;https://www.lifewire.com/uses-of-linux-ls-command-4054227&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;internalLink&amp;quot; data-ordinal=&amp;quot;1&amp;quot;&amp;gt;the ls command&amp;lt;/a&amp;gt; to list all the files in a folder in a long format along with the time command.&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time ls -l&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The results from the time command will be as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;real 0m0.177s&amp;lt;br/&amp;gt;user 0m0.156s&amp;lt;br/&amp;gt;sys 0m0.020s&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The statistics shown show the total time is took to run the command, the amount of time that was spent in &amp;lt;a href=&amp;quot;http://www.linfo.org/user_mode.html&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;externalLink&amp;quot; data-ordinal=&amp;quot;2&amp;quot; rel=&amp;quot;nofollow&amp;quot;&amp;gt;user mode&amp;lt;/a&amp;gt; and the amount of time spent in &amp;lt;a href=&amp;quot;http://www.linfo.org/kernel_mode.html&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;externalLink&amp;quot; data-ordinal=&amp;quot;3&amp;quot; rel=&amp;quot;nofollow&amp;quot;&amp;gt;kernel mode&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you have a program that you have written and you want to work on performance you can run it along with the time command over and over and try and improve on the statistics.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;By default the output is displayed at the end of the program but perhaps you want the output to go to a file.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To output the format to a file use the following syntax:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time -o &amp;amp;lt;filetowriteto&amp;amp;gt; &amp;amp;lt;command&amp;amp;gt; &amp;amp;lt;command switches&amp;amp;gt;&amp;lt;br/&amp;gt;time --output&amp;amp;#61;&amp;amp;lt;filetowriteto&amp;amp;gt; &amp;amp;lt;command&amp;amp;gt; &amp;amp;lt;command switches&amp;amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;All of the switches for the time command must be specified before the command you wish to run.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you are performance tuning then you may wish to append the output from the time command to the same file over and over so that you can see a trend.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;To do so use the following syntax instead:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time -a &amp;amp;lt;filetoappendto&amp;amp;gt; &amp;amp;lt;command&amp;amp;gt; &amp;amp;lt;command switches&amp;amp;gt;&amp;lt;br/&amp;gt;time --append &amp;amp;lt;filetoappendto&amp;amp;gt; &amp;amp;lt;command&amp;amp;gt; &amp;amp;lt;command switches&amp;amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;h3&amp;gt;Formatting The Output Of The Time Command&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;By default the output is as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;real 0m0.177s&amp;lt;br/&amp;gt;user 0m0.156s&amp;lt;br/&amp;gt;sys 0m0.020s&amp;lt;br/&amp;gt;\u00A0&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;There are a large number of formatting options as shown by the following list&amp;lt;/p&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;C - Name and command line arguments used&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;D - Average size of the process&amp;amp;#39;s unshared data area in kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;E - Elapsed time in a clock format&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;F - Number of page faults&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;I - Number of file system inputs by the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;K - Average total memory use of the process in kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;M - Maximum resident set size of the process during the lifetime in Kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;O - Number of file system outputs by the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;P - Percentage of CPU that the job received&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;R - Number of minor or recoverable page faults&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;S - Total number of CPU seconds used by the system in kernel mode&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;U - Total number of CPU seconds used by user mode&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;W - Number of times the process was &amp;lt;a href=&amp;quot;http://www.dictionary.com/browse/swap&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;externalLink&amp;quot; data-ordinal=&amp;quot;4&amp;quot; rel=&amp;quot;nofollow&amp;quot;&amp;gt;swapped out of main memory&amp;lt;/a&amp;gt; &amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;X - Average amount of shared text in the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Z - System&amp;amp;#39;s page size in kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;c - Number of times the process was &amp;lt;a href=&amp;quot;http://www.linfo.org/context_switch.html&amp;quot; data-component=&amp;quot;link&amp;quot; data-source=&amp;quot;inlineLink&amp;quot; data-type=&amp;quot;externalLink&amp;quot; data-ordinal=&amp;quot;5&amp;quot; rel=&amp;quot;nofollow&amp;quot;&amp;gt;context switched&amp;lt;/a&amp;gt; &amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;e - Elapsed real time used by the process in seconds&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;k - Number of signals delivered to the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;p - Average unshared stack size of the process in kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;r - Number of socket messages received by the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;s - Number of socket messages sent by the process&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;t - Average resident set size of the process in kilobytes&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;w - Number of time the process was context switched voluntarily&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;x - Exit status of the command&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;p&amp;gt;You can use the formatting switches as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time -f &amp;amp;#34;Elapsed Time &amp;amp;#61; %E, Inputs %I, Outputs %O&amp;amp;#34; &amp;amp;lt;command&amp;amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The output for the above command would be something like this:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;Elapsed Time &amp;amp;#61; 0:01:00, Inputs 2, Outputs 1&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;You can mix and match the switches as required.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;If you want to add a new line as part of the format string use the newline character as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;time -f &amp;amp;#34;Elapsed Time &amp;amp;#61; %E \\n Inputs %I \\n Outputs %O&amp;amp;#34; &amp;amp;lt;command&amp;amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;h3&amp;gt;Summary&amp;lt;/h3&amp;gt;&amp;lt;p&amp;gt;To find out more about the time command read the Linux Manual Page by running the following command:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;man time&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;&amp;lt;p&amp;gt;The format switch doesn&amp;amp;#39;t work straight away within Ubuntu. You need to run the command as follows:&amp;lt;/p&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;p&amp;gt;/usr/bin/time&amp;lt;/p&amp;gt;&amp;lt;/blockquote&amp;gt;"^^<http://www.w3.org/2001/XMLSchema#string>
<https://www.lifewire.com/command-return-time-command-4054237>