Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 2038  / 3 Years ago, mon, september 20, 2021, 10:29:08

Is there any way to find out top 10 most used commands in history? Here top 10 means commands which I have used most of the time i.e. the commands whose used count is more than others.


More From » bash

 Answers
0

I have a little script myself to check what are the top N commands I have been using lately:



mylast () {
re='^[0-9]+$'
if ! [[ $1 =~ $re ]] ; then
echo "error: $1 not a number" >&2
else
history | awk '{a[$2]++} END {for (i in a) print a[i], i}' | sort -rn | head -n $1
fi
}


So by saying mylast 10 it shows the top 10.



This is done by going through the history and storing the 2nd field into in awk, so that the count can be tracked through an array.



Sample output:



$ mylast 5
248 git
107 python
93 grep
71 awk
52 less

[#17997] Tuesday, September 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibuteking

Total Points: 35
Total Questions: 128
Total Answers: 138

Location: Indonesia
Member since Thu, Oct 1, 2020
4 Years ago
;