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 - 使用
commandcommand time wc /etc/hosts
本文介绍了Bash shell中的time关键字和/usr/bin/time命令的区别。time作为shell关键字用于简单报告管道的执行时间,而/usr/bin/time提供更详细的资源使用情况,包括真实时间、用户CPU时间和系统CPU时间。要使用外部time命令,需要显式指定路径或者通过或command来避免使用shell内置。文章还提到了调用/usr/bin/time的不同方式,并强调了在bash中正确使用这两个时间工具的注意事项。
2900

被折叠的 条评论
为什么被折叠?



