shell - 打印 shell 命令的执行时间

标签 shell command-line

是否可以使用以下组合打印 shell 命令的执行时间?

root@hostname:~# "command to execute" && echo "execution time"

最佳答案

time是大多数 shell 中的内置命令,用于将执行时间信息写入 tty。

你也可以尝试类似的东西

start_time=`date +%s`
<command-to-execute>
end_time=`date +%s`
echo execution time was `expr $end_time - $start_time` s.

或在 bash :
start_time=`date +%s`
<command-to-execute> && echo run time is $(expr `date +%s` - $start_time) s

关于shell - 打印 shell 命令的执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1656425/

相关文章:

linux - Stat 命令将具有更改日期的文件列入候选名单

linux - 通过 Linux 命令行提取 file_name.zip.001

unix - 在 UNIX shell 脚本中 : What does $! 扩展到?

firefox - 从命令行选择 Firefox 中的选项卡

c++ - 从 msvc c++ 执行控制台应用程序

vim - 在 vim 中,如何将 "args"设置为 "grep -l"的结果?

batch-file - 如何在批处理文件中运行多个命令?

node.js - 为什么 npm install 在 git bash 上不起作用

bash - 在 zsh 上运行 bash 脚本不会获取环境变量

shell - 批量重命名子目录中的文件扩展名