Print the top most used commands from the history using awk

Write tutorials here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Please don't add support questions to tutorials,start your own thread in the appropriate sub-forum instead. Before you post please read this
Post Reply
kwyrky
Level 3
Level 3
Posts: 118
Joined: Wed Jul 10, 2019 5:10 am

Print the top most used commands from the history using awk

Post by kwyrky »

This is not a tutorial but a useful command at least for me and I wanted to share for others :D

Code: Select all

history | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | sort | uniq -c | sort -nr | head -25
So what this does is to use the history command piped to awk which only removes the command number and reprints the command without it. After that the resulting lines are sorted by sort. The uniq -c command removes doubles and counts the occurrences which we want to know. We sort this result again with sort -nr and finally we grab the top 25 commands of the result with head -25.
Post Reply

Return to “Tutorials”