Home Linux Commands How To Find Top Most Used Commands On Linux

How To Find Top Most Used Commands On Linux

By sk
Published: Last Updated on 2.9K views

The other day a fellow Linux user and I were discussing about Linux commands. He asked me which Linux command I use the most. I told him that one of my most frequently used command is sudo. I use it everyday to install, update, remove packages and other administrative tasks on my Linux box. I guess "sudo" is the most frequently used command of many Linux users. If you ever wondered what's your top most used commands on Linux, here is how to find them.

Find Top Most Used Commands On Linux

As you know, the history file (~/.bash_history) keeps a record of all the commands you run in the Terminal. You can easily find which commands you use the most by referring this file.

Let me show you the top 5 most used commands on my Linux box:

$ history | awk '{print $2}' | sort | uniq -c | sort -nr | head -5

Sample output:

153 sudo
118 pngquant
33 cd
30 ssh
29 exit

Let us break down the above command and see what each option does.

  • The "awk '{print $2}'" command prints first string from the history file without showing command options and arguments.
  • The "sort" command orders all lines alphabetically.
  • The "uniq -c" command removes the duplicate lines (typed commands) and count them.
  • And, the last "sort -nr" command displays the commands in reverse order by the count number returned by "uniq" command.

Heads Up: You can use ExplainShell to find what each part of a command does.

As you can see, "sudo" is the top most used command and I have used it 153 times. And "exit" is the least used command.

I have sorted the result in descending order (reverse) i.e largest to smallest. To display the top most used command in ascending order (smallest to largest), use this command instead:

$ history | awk {'print $2'} | sort | uniq -c | sort -n | tail -n5

Sample output:

29 exit
30 ssh
33 cd
118 pngquant
153 sudo
Find top most used commands on Linux
Find top most used commands on Linux

Here is the another version of same command which shows little bit extra details:

$ 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 -n5
     1	177  17.7177%   pngquant
     2	173  17.3173%   vagrant
     3	101  10.1101%   cd
     4	71   7.10711%   sudo
     5	47   4.7047%    ffmpeg

If you don't want to limit the number of results, simply remove the last (head or tail) part of the above commands:

$ history | awk '{print $2}' | sort | uniq -c | sort -nr

The aforementioned commands are Bash-specific. If you're on Fish shell, run:

$ history | cut -d ' ' -f 1 | sort | uniq -c | sort -nr | head -5

Now, it's your time. Go and find out your top most frequently used commands on your Linux box.

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More