Fundamentals 5 min read

How to Quickly Find Your Most Frequently Used Linux Commands

This guide shows how to extract the top commands you run in Linux by parsing the ~/.bash_history file with a pipeline of history, awk, sort, uniq, and head, and explains each step, sample output, and how to adjust sorting order.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Quickly Find Your Most Frequently Used Linux Commands

Linux records every command you type in the ~/.bash_history file. By processing this file you can discover which commands you use most often.

Command to list the top 5 most used commands

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

This pipeline works as follows: history – prints the command history. awk '{print $2}' – extracts the second column (the command name) while ignoring options and arguments. sort – sorts the command names alphabetically. uniq -c – collapses duplicate lines and prefixes each with its occurrence count. sort -nr – sorts the counted list numerically in reverse order (most frequent first). head -5 – shows only the top five entries.

Typical output looks like:

153 sudo
118 ls
33 cd
30 ssh
29 git

The result clearly shows sudo as the most frequently used command (153 times in this example).

Understanding each part of the pipeline

The history command on Ubuntu produces lines such as:

743 sudo apt-get update
744 sudo apt-get upgrade
745 ls
747 ls
748 git status

On other distributions (e.g., CentOS) the format may differ slightly, but the same pipeline works after minor adjustments.

Alternative: list commands in ascending order

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

This variant sorts the counts in ascending order and shows the five least used commands.

Customizing the result

If you want to see all commands without limiting the number, simply omit the final head or tail part:

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

For detailed explanations of each command option you can use ExplainShell.

Now you can run the appropriate command on your own system to discover which Linux commands you rely on most.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

historyShellBashcommand-lineawk
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.