time
time
是bash的shell keyword,而不是 shell buildin
可以使用命令help time
查看这个time 关键字的使用方法
time: time [-p] pipeline
Report time consumed by pipeline's execution.
Execute PIPELINE and print a summary of the real time, user CPU time,
and system CPU time spent executing PIPELINE when it terminates.
Options:
-p print the timing summary in the portable Posix format
The value of the TIMEFORMAT variable is used as the output format.
Exit Status:
The return status is the return status of PIPELINE.
简单来说就是:可以检测一个管道的执行时间。
/usr/bin/time
/usr/bin/time
是一个二进制可执行文件,是“真正”的time 命令,用来运行并且显示一个程序的资源使用情况。
其实在time 命令的使用手册中(man time)也告诉我们,bash 的使用者需要显式调用该命令。
Users of the bash shell need to use an explicit path in order to run
the external time command and not the shell builtin variant. On system
where time is installed in /usr/bin, the first example would become
/usr/bin/time wc /etc/hosts
调用/usr/bin/time 的几种方法
- 显式调用
/usr/bin/time wc /etc/hosts
- 使用
\
让shell忽略别名(alias)和关键字(keywords)\time wc /etc/hosts
- 使用
command
command time wc /etc/hosts