Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

history, a command to display your last used commands

Date: 2008-12-20 00:00:00 -0400

History is a great command to use, I use it daily, today I have found a real good application of it.

It is the way to list the most used commands by you.

Here is how, type this in the console:

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r

What this command does is to pass the output of history to awk, which prints only the second column of it, then it sorts it and count the occurrences of each command, finally it sorts the output in reverse order, so you have first your most used command and at last the least used one, if you want the opposite order try this one:

history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort

You can use history also with grep, if you want to look for an specific command like:

mount 192.168.1.1:/home/user /media/nfs

Which is too long to type again, and you may not remember it, so you can look for it using:

history | grep mount

but if you use it or other command a lot, is better to create an alias for it.

This article is inspired, and with info from: LifeHacker

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.