Linux 编写Shell脚本统计当前用户最常用的前五个指令及其次数

大致思路是这样的,可以根据实际情况修改。

history:输出历史记录,我看了一下,连续输入同样的命令,history只会记录一条。若有更符合需求的历史数据源,可替换。

awk '{print $2}':截取历史记录中的命令列。

sort:排序

uniq -c:去重并统计次数

sort -nr:排序,根据次数倒序

head -n5:取前5行

awk '{print $2" "$1}':格式化,命令在前,次数在后。

history|awk '{print $2}'|sort|uniq -c|sort -nr|head -n5|awk '{print $2" "$1}'

history |awk '{if($2~/^[a-zA-Z]/) print $2}'|sort |uniq -c|sort -nrk1|awk 'NR<6{print $2,$1}'

history|awk '{print $2}'|sort|uniq -c|head -5

 

请问命令的历史记录保存在哪里?

这道题原题呀

是不是,哈哈哈哈哈哈