'Display n most frequent used commands Linux [closed]

A command in linux to list the top N most frequent commands used in your zsh.

zsh


Solution 1:[1]

In zsh

fc -ln 0 | awk '{print $1}' | sort | uniq -c | sort -nr | head -<X>

fc -ln 0 - show the history
awk - prints only the command without the arguments
sort - for using the next pipe
uniq -c - count uniques commands
sort -rn - sort by number in reverse
head -<X> - list the top X

similar to bash

history | awk '{print $2}' | sort | uniq -c | sort -rn| head -<X>

Special thanks to @ericbn

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1