bash most used history function 1

bash most used history function

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl |  head -n10

Here is what the above code is Doing:
1. The history command is used to list the commands that have been used in the current session.
2. The awk command is used to count the number of times each command has been used.
3. The output of the awk command is piped to the grep command to filter out the commands that start with a dot.
4. The output of the grep command is piped to the column command to format the output.
5. The output of the column command is piped to the sort command to sort the output in descending order.
6. The output of the sort command is piped to the nl command to add line numbers to the output.
7. The output of the nl command is piped to the head command to display only the top 10 commands.

Similar Posts