Print execution time of a shell command

2020-02-16 06:25发布

Is is possible to print the execution time of a shell command with following combination?

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

8条回答
Animai°情兽
2楼-- · 2020-02-16 06:47

Adding to @mob's answer:

Appending %N to date +%s gives us nanosecond accuracy:

start=`date +%s%N`;<command>;end=`date +%s%N`;echo `expr $end - $start`
查看更多
看我几分像从前
3楼-- · 2020-02-16 06:51

In zsh you can use

=time ...

In bash or zsh you can use

command time ...

These (by different mechanisms) force an external command to be used.

查看更多
登录 后发表回答