List Your 15 Most Used Terminal Commands

Nov 2, 2012 - 17 Comments

Discovering most used Terminal commands with history

The history command is a useful way to find specific commands that have been used in the past, and it can also be used to discover what your personal most used commands are with the following command string:

history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head -15

The output strips any flags or parameters, providing only the root commands shown by the most commonly used. Example output may look like the following:

$ history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn |head -n 15
56 traceroute
35 nslookup
35 ssh
31 ls
28 curl
25 sftp
23 gcc
23 make
18 cd
18 cat
17 round
15 python
13 kill
13 clear
10 defaults

The number to the left indicates how many times the command has been used, per what is listed in bash history. Clearing bash history will obviously change those numbers, as will any adjustments to the length of commands stored in bash_history, and having it disabled completely will obviously cause the entire command to report back nothing.

If you’d rather see the most used complete commands, perhaps to make aliases or for another purpose, simplifying the command string by removing awk will accomplish that;

history | sort -rn | head

Leaving the -n flag off of ‘head’ will default to list 10 items, but any number can be applied by specifying it with -n.

These commands will work in OS X and Linux, and should work in other unix variations as well.

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

17 Comments

» Comments RSS Feed

  1. Ivan says:

    101 cd
    91 ls
    37 scp
    36 pwd
    30 sudo
    28 ssh
    16 cat
    13 mv
    12 .
    11 rm
    9 route
    8 export
    7 vi
    7 traceroute
    6 tar

  2. Fernando says:

    history | sort -rn | head
    only shows the last 10 commands, not the most used…

  3. Usman Arif says:

    108 ping
    12 top
    7 cd
    4 ls
    3 pwd
    3 Unzip
    2 trace
    2 telnet
    2 history
    1 wget
    1 uptime
    1 unzip
    1 uncompress
    1 unarchiver
    1 tracert

  4. Travis says:

    177 sudo
    34 man
    24 cd
    23 ls
    19 java
    17 killall
    17 diskutil
    14 ping
    14 defaults
    10 ssh
    10 osascript
    9 shutdown
    9 kill
    9 clear
    7 top

  5. Daniel Black says:

    949 mina
    503 curl
    278 ssh
    205 mate
    204 cd
    186 git
    92 rspec
    92 bundle
    84 rake
    68 vagrant
    61 httrack
    53 open
    49 ls
    47 rvm
    44 cat

    *mina – is a deployment tool similar to capistrano

  6. sbarex says:

    112 hg
    72 sudo
    32 port
    24 curl
    23 scp
    21 ping
    21 ll
    18 ssh
    18 cd
    12 open
    12 less
    11 vi
    9 man
    8 sh/build_locale.sh
    7 /Applications/XAMPP/xamppfiles/bin/php

  7. Zol says:

    2999 git
    1271 cd
    1242 ls
    391 rm
    374 mvn
    304 cat
    235 vi
    203 ps
    184 sudo
    118 mv
    117 ping
    116 brew
    107 ssh
    98 cp
    89 mvim

  8. Ben says:

    127 grep
    72 cd
    65 ls
    34 mv
    34 cp
    16 ssh
    16 find
    15 rsync
    13 clear
    13 cat
    10 identify
    10 history
    8 sudo
    8 mysqldump
    8 mkdir

  9. Willie ElCamino says:

    oh – sorry, i did it wrong…

    65 rm
    61 ls
    60 sudo
    49 brew
    25 exit
    22 ssh
    21 port
    20 cd
    19 man
    19 cowsay
    15 clear
    10 su
    9 uptime
    8 htop
    7 df

  10. Willie ElCamino says:

    in no particular order –
    1. su
    2. softwareupdate -l
    3. softwareupdate -i-a
    4. brew install
    5. brew update
    6. brew upgrade
    7. brew search
    8. df-hT
    9. rm -rf .Trash/*
    10. cd
    11. ls
    12. locate
    13. locate.updatedb
    14. ssh
    15. cowsay “i wish i was running debian”
    16. htop

  11. John Harlow says:

    Odd; I don’t see vi or any for or while loops

  12. err says:

    Sudo
    defaults
    telnet

  13. toto says:

    Interesting, thanks.

  14. Eduu says:

    65 ping
    48 git
    36 ls
    34 python
    27 cat
    23 sudo
    22 ssh
    16 dscacheutil
    16 clear
    15 terminal-notifier
    12 hostname
    12 defaults
    10 purge
    9 cp
    8 top

  15. Oleh says:

    709 s
    546 git
    227 d
    143 ll
    135 rake
    117 pwd
    114 gpull
    107 cd
    94 gpush
    85 ssh
    84 subl
    44 cap
    43 cat
    32 bundle
    30 brew

  16. bubbleg5 says:

    19 ping
    17 sudo
    3 java
    2 ssh
    2 purge
    2 nslookup
    2 exit
    1 open
    1 man
    1 killall
    1 history
    1 font_cache
    1 defaults

  17. Zerafiall says:

    79 defaults
    73 cd
    50 diskutil
    43 ls
    43 killall
    27 purge
    27 open
    24 mv
    24 df
    23 mdfind
    20 rm
    12 cp
    7 sudo
    6 itunes
    5 chflags

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site