Linux Shell 计算脚本执行过程用了多长时间

在脚本中很实用。感受不错就转载了。ide

1.应用场景优化

当脚本中涉及大文件或多文件的解压压缩时,等待时间过长,最好加上执行过程耗时,以便后期优化和下一步操做。code

2.解决办法it

starttime=date +'%Y-%m-%d %H:%M:%S'
#执行程序
endtime=date +'%Y-%m-%d %H:%M:%S'
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间: "$((end_seconds-start_seconds))"s"
 class

相关文章
相关标签/搜索