How can I make a list with most used commands in terminal?
I know that this question may be unuseful for any future proposals for some of us, but even like this, the list can be useful when we don't remember a command used once or some times in the past, when we can search at the end of this list.
We will use the records from
.bash_history
file to do this. The next command will give you a list of all commands in order that you used them most often:If you want only top 10, you must to add
head
at the command above:To get a specific top, for example top 5, use
head
with-n 5
option:If you want the list in reverse order (top with the rarely used commands), don't use
r
oprion for secondsort
:And finally to get a list with the commands used once for example, use
grep ' 1 '
(change1
with the desired number):To deal with
sudo
commands (likesudo vim foo
), instead of just{print $3}
in the awk command, use:So the entire command would look like:
For example:
You can see the jump in counts for
vim
,rm
, etc.Below command will also list the
top 10
most frequently used terminal commands,Command to list all the commands which are most oftenly used in terminal,
Fish & Bash - The question doesn't specify a specific shell, just 'terminal'. Change head to whatever number you want.
Fish
history | awk '{print $1}' | sort | uniq --count | sort --numeric-sort --reverse | head -10
This Bash one seems to work and is a bit shorter and easier to understand than the other answers. I like the long options to help readability in these types of examples.
Bash
history | awk '{print $2}' | sort | uniq --count | sort --numeric-sort --reverse | head -10