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

How To Find Top Most Used Commands On Linux

By sk
416 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 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 typed 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.

Bonus tip:

  • 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

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

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

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

Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

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. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More