找出最常用的10条history命令的shell脚本
从~/.bash_history中获得命令列表,只需要命令名称即可,而不需要命令参数,接着统计每条命令的出现次数,然后找出出现次数最多的10条命令。
实现的脚本如下(find_history.sh):
#!/bin/bash
#文件名:find_history.sh
#用途:列出最常使用的10条命令
printf "COMMAND\t\COUNT\n";
cat ~/.bash_history | awk '{ list[$1]++; } \
END{
for(i in list)
{
printf("%s\t%d\n",i,list[i]); }
}' | sort -nrk 2 | head
输出结果样例:
$ ./find_history.sh
COMMAND COUNT
ping 80
ls 56
cat 35
ps 34
sudo 27
du 26
cd 26
ssh 22
sftp 22
clear 21
您可能感兴趣的文章:
找出最常用的10条history命令的shell脚本
history命令的15个实例
inux shell初级入门教程
深入解析tcsh的初始化配置文件
Bash显示history记录中命令执行时间的方法
用shell脚本找出文件中包含指定字段的文件(图文)
为history添加时间戳格式
linux shell自定义函数与变量作用域
python shell是什么
linux shell学习之shell流程控制