是否可以使用以下组合打印 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/