How To List Your Most Used Commands In Terminal?


Short Bytes: Using the history command in bash shell, you can get a list of all the commands that you’ve run previously on your machine. Going one step further, you can even list the most used commands in terminal. For doing this, the records from .bash_history file is used.

If you mainly use Linux for work and other purposes, there is no escape and you’re bound to spend a lot of time on the bash, which is the default command line on many Linux distributions. This also goes without saying that you must be using a lot of commands again and again, and that could be an issue for some people.

To deal with this, bash shell comes with some useful functions that can help you access old commands with ease. For those who don’t know, the history file is updated every time you exit a terminal session. In this article, I’ll tell you how to make a list of the most used commands in terminal and some other useful bash shell tips. Before moving ahead, we would like you to take a look at our list of A to Z Linux commands.

Listing command history in bash is a very basic command, and you must be familiar with it. The simple history command lists the last certain number of commands.


You can also populate the list of last x number of commands by using a number. For example:

history 11

There are many ways to do so but using grep is my favorite method. Simply run the following command to search the needed commands in the history list.

history | grep command_to_be_search

How to make a list of the most used commands in terminal?

Some of you might not find this tip particularly useful but it’s always a good idea to review your work and get to know about the commands you use the most. As I’m preparing this tutorial on a fresh installation of Ubuntu, you won’t be seeing tons of commands in my list.

We can use the bash history file to perform this action. I came across a fine tip on AskUbuntu and decided to share the same with you. You can use the following command to list the commands you use the most:

history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr

You can also get the top x (10, 20, or other number) commands by using head with -n x command. For example, to list top 5 most used commands:

history | awk 'BEGIN {FS="[ \t]+|\\|"} {print $3}' | sort | uniq -c | sort -nr | head -n 5

I hope that you would have found this bash history tip to list most useful commands in terminal useful.

What are your favorite commands? Tell us in comments below.

Also Read:10 Most Dangerous Linux Commands You Should Never Run
Adarsh Verma

Adarsh Verma

Fossbytes co-founder and an aspiring entrepreneur who keeps a close eye on open source, tech giants, and security. Get in touch with him by sending an email — [email protected]
More From Fossbytes

Latest On Fossbytes

Find your dream job