有时候为了达到同一结果,但有多种不同的办法能够执行,因此想要了解不同命令执行,哪个使用CPU、内存、时间最少
实现方法
time
-v: 显示更加详细信息
示例
- 统计运行时间
]# time touch {1..100}.txt
- 统计运行时间结果重定向-使用子shell"() &>/path/to/info.txt"
]# (time for i in `ls /data/images/`;do find /data -type f -name "$i"|xargs rm -f;done) &> /data/info.txt
]# cat /data/info.txt
real 0m0.194s
user 0m0.033s
sys 0m0.158s
- 统计运行时间结果重定向-使用"{ time <command>; } &>/path/to/info.txt"
注意花括号中的空格和分号
]# { time find ./ -name "*.txt" ;} &>/data/info.txt
]# cat /data/info.txt
... #省略
./99.txt
./100.txt
real 0m0.001s
user 0m0.001s
sys 0m0.000s