每天一个小练习--打印出10条最常用的命令

打印出10条最常用的命令。

#cat top10.sh

#! /bin/bash
#top10.sh
printf "COMMAND\tCOUNT\n"
cat ~/.bash_history | awk '{list[$1]++; }
END{
for (i in list)
{
printf ("%s\t%d\n",i,list[i]);}
}' | sort -nrk2 | head

#./top10.sh


其实也可以这样:

# cat ~/.bash_history | awk '{print $1}'  | sort | uniq -c | sort -nr | head

你可能感兴趣的:(printf,sort,.bash_history)