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

See most used commands

It will return a ranked list of your most commonly-entered commands using your command history
Sample Output
8 wine
      8 kill
      7 killall
     66 cd
      5 wget
      4 telnet

7
By: kayowas
2009-04-05 13:40:56

These Might Interest You


  • 7
    compgen -c | sort -u > commands && less commands
    Habitual · 2012-04-27 14:19:05 1
  • Obviously, you can replace 'man' command with any command in this command line to do useful things. I just want to mention that there is a way to list all the commands which you can execute directly without giving fullpath. Normally all important commands will be placed in your PATH directories. This commandline uses that variable to get commands. Works in Ubuntu, will work in all 'manpage' configured *nix systems. Show Sample Output


    3
    find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
    mohan43u · 2009-06-13 19:56:24 1
  • Put this in your bash startup script so you can quickly remember the top rated commands on CommandLineFu's website. Put it in .bashrc on Linux, or .bash_profile on OSX. Show Sample Output


    0
    alias fu='curl -s http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext | grep -vE "^$|^#"'
    kordless · 2012-04-16 05:53:56 0
  • Faster then other method using wget For obtain all commands use nu=`curl http://www.commandlinefu.com/commands/browse |grep -o "Terminal - All commands -.*results$" | grep -oE "[[:digit:],]{4,}" | sed 's/,//'`; curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-"$nu":25] | grep -vE "_curl_|\.com by David" > clf-ALL.txt For more version specific nu=`curl http://www.commandlinefu.com/commands/browse |grep -o "Terminal - All commands -.*results$" | grep -oE "[[:digit:],]{4,}" | sed 's/,//'`; curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-"$nu":25] | grep -vE "_curl_|\.com by David" > clf-ALL_"$nu".txt Also download dirctly from my dropbox My drop box invitaion link is http://db.tt/sRdJWvQq . Use it and get free 2.5 GB space. Show Sample Output


    2
    curl http://www.commandlinefu.com/commands/browse/sort-by-votes/plaintext/[0-9000:25] | grep -vE "_curl_|\.com by David" > clf-ALL.txt
    totti · 2011-11-08 12:19:48 0
  • Uses history to get the last n+1 commands (since this command will appear as the most recent), then strips out the line number and this command using sed, and appends the commands to a file.


    1
    history | tail -(n+1) | head -(n) | sed 's/^[0-9 ]\{7\}//' >> ~/script.sh
    unixmonkey15842 · 2011-06-08 13:40:58 0
  • Most of the "most used commands" approaches does not consider pipes and other complexities. This approach considers pipes, process substitution by backticks or $() and multiple commands separated by ; Perl regular expression breaks up each line using | or < ( or ; or ` or $( and picks the first word (excluding "do" in case of for loops) note: if you are using lots of perl one-liners, the perl commands will be counted as well in this approach, since semicolon is used as a separator Show Sample Output


    4
    history | perl -F"\||<\(|;|\`|\\$\(" -alne 'foreach (@F) { print $1 if /\b((?!do)[a-z]+)\b/i }' | sort | uniq -c | sort -nr | head
    alperyilmaz · 2010-04-08 13:46:09 1

What Others Think

Already posted in a shorter version http://www.commandlinefu.com/commands/view/869/list-of-commands-you-use-most-often
TheMightyBuzzard · 476 weeks and 4 days ago
@TheMightyBuzzard: I tested both commands under OS X and found kayowas' version more accurate: It correctly handles command such as: ls|grep "foo" where the pipe symbol immediately follows the command.
haivu · 476 weeks and 4 days ago
I bet "cd" and "ls" will be the top commands in most of our readers lists ;)
bytor4232 · 476 weeks and 3 days ago
I think awk '{print $1}' approach is not accurate for counting commands in pipes. So, I propose the following(*) for the most accurate counting: ....|perl -F'\|' -ane 'foreach $pipe (@F) {$pipe=~ /\s*(\w+?)\s/;print $1,"\n";} ' | sort | uniq -c | sort -nr | head Below is comparison of top 10 commands My method kayowas' method 1023 sudo 1003 sudo 970 perl 894 cd 904 cd 657 nano 668 nano 617 perl 624 awk 593 ls 601 ls 498 cat 601 grep 351 history 569 cat 293 man 499 cut 284 head 457 head 276 find (*) print history without the line numbers
alperyilmaz · 476 weeks and 3 days ago
sorry, spaces and tabs are lost, i'm posting the results again: My method ----- kayowas' method 1023 sudo --- 1003 sudo 970 perl ----- 894 cd 904 cd ------- 657 nano 668 nano ----- 617 perl 624 awk ------ 593 ls 601 ls ------- 498 cat 601 grep ----- 351 history 569 cat ------ 293 man 499 cut ------ 284 head 457 head ----- 276 find Notice absence of awk, cut and grep in kayowas' method.
alperyilmaz · 476 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: