执行这个命令后,ping 命令的输出结果依然会在终端里,而 time 命令的结果就写入到我们所指定的 time-output.txt 文件里。
-o
选项表示输出文件不存在就创建,如果存在的话就直接覆盖重写。如果我们不想覆盖重写,而是想追加在文件后面,我们可以使用
-a
选项。
$ /usr/bin/time -a /home/smart/time
-output.txt ping linoxide.com
3. 显示更详细的时间信息
time 命令不带选项的话,显示的信息量比较少,如果我们想获得更详细的信息,那么我们可以使用
-v
选项。
$ /usr/bin/time -v ping baidu.com PING baidu.com (123.125.114.144) 56(84) bytes of data. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=56time=2.75 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=56time=2.76 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=3 ttl=56time=2.85 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=4 ttl=56time=2.77 ms ^C --- baidu.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time3300ms rtt min/avg/max/mdev = 2.751/2.785/2.851/0.075 ms Command being timed: "ping baidu.com" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 0% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:03.64 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): 2140 Average resident set size (kbytes): 0 Major (requiring I/O) page faults: 0 Minor (reclaiming a frame) page faults: 626 Voluntary context switches: 10 Involuntary context switches: 0 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
C - Name and command line arguments used D - Average size of the process's unshared data area in kilobytes E - Elapsed time in a clock format F - Number of page faults I - Number of file system inputs by the process K - Average total memory use of the process in kilobytes M - Maximum resident set the size of the process during the lifetime in Kilobytes O - Number of file system outputs by the process P - Percentage of CPU that the job received R - Number of minor or recoverable page faults S - Total number of CPU seconds used by the system in kernel mode U - Total number of CPU seconds used by user mode W - Number of times the process was swapped out of main memory X - Average amount ofsharedtextin the process Z - System's page size in kilobytes c - Number of times the process was context-switched e - Elapsed real time used by the process in seconds k - Number of signals delivered to the process p - Average unshared stack size of the process in kilobytes r - Number of socket messages received by the process s - Number of socket messages sent by the process t - Average resident set size of the process in kilobytes w - Number of time the process was context-switched voluntarily x - Exit