How to Find the Most Used Commands in Your Linux System

Linux TLDR
Last Updated:
Reading time: 2 minutes

As a Linux administrator or a normal user, you often have to execute multiple commands in your terminal emulator like Gnome Terminal or Konsole for different purposes.

But have you ever wondered which command you are executing repeatedly without being aware of it? So, don’t worry if this thought did not come to your mind before or until you found this article.

In this article, you will learn how to find and list the most (including least) used commands in your Linux system.

Tutorial Details

DescriptionFinding the Most Used Commands in Linux
Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisiteshistory
Internet RequiredNo

Find the Top Most Used Commands on Linux

You might already be aware of the β€œ~/.bash_history” file that stores the record of each command executed in your terminal, and you use the history command to output the stored records in that file.

That file can also be used to find the most frequently used commands in your Linux system.

For example, the following multiple commands were conjoined (piped) with each other to list the top 10 most used commands in my Linux system.

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

Output:

Listing the top most executed commands in my Linux box

Command breakdown:

  • β€œawk '{print $2}'β€œ: It will print the first string from the history file by excluding the options and arguments.
  • β€œsortβ€œ: Sort all the lines in alphabetical order.
  • β€œuniq -cβ€œ: Remove the duplicate commands and count their occurrences.
  • β€œhead -10β€œ: Prints only the first 10 lines of the piped output in reverse order.

As you can see in the above picture, the most executed command in my Linux system is the sudo command, which has been executed β€œ89” times since the user account was created (except if the history is cleared using the β€œhistory -c” command).

After that, the most used command is β€œlsβ€œ, and the least executed command is β€œfileβ€œ, which has been executed only seven times.

If you want to reverse the order from least to most commands, then execute the following command.

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

Output:

Listing the least executed commands in my Linux box

Instead of truncating the output into ten results, you can list all the most (or least) executed commands in your Linux system by removing the head and tail commands.

For example, the following command will list all the most executed commands in my Linux system without any filter.

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

Output:

Listing all the most executed commands in my Linux box without any filter

And you can do the same while listing the least executed commands from your system without any filter.

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

Output:

Listing all the least executed commands in my Linux box without any filter

Lastly, you can use the following one line awk scripts to get extra information like an index number, the number of times commands were executed in integer and percent format, and the user-defined command.

$ 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

Output:

Finding the most executed command with extra details

That’s all for now.

Check your most and least executed commands in your Linux system and let me know in the comment section; for me, you already know from the above pictures.

Peace!!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.