My Top Ten Linux Commands (History)

Thanks to Luna I have a new blog entry, my top ten used commands, in terminal. First the code;

[coolcode]history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c | sort -n | tail | sort -nr[/coolcode]

Top Ten on Desktop

One being the most used.

  1. ls
  2. cd
  3. killall
  4. conky
  5. sudo
  6. vi
  7. ssh
  8. rm
  9. top
  10. ping

Top Ten on Server

One being the most used.

  1. ls
  2. sudo
  3. cd
  4. mv
  5. rm
  6. vi
  7. tar
  8. wget
  9. chmod
  10. cp

The ''script''

[coolcode]history[/coolcode]
Many programs read input from the user a line at a time. The GNU History library is able to keep track of those lines, associate arbitrary data with each line, and utilize information from previous lines in composing new ones.

[coolcode]| [/coolcode]
I/O Redirection

[coolcode]awk '{print $2}' |[/coolcode]
AWK (mawk) is pattern scanning and text processing language. Field number 2 is accessed with $2. (I/O Redirection)

[coolcode]awk 'BEGIN {FS="|"} {print $1}'|[/coolcode]
Awk to process (again). If 'FS = ' then mawk breaks the record into individual characters/records. Then BEGIN is implicity matching and requires an action.

[coolcode]sort|[/coolcode]
Write sorted concatenation of all FILE(s) to standard output.

[coolcode]uniq -c | sort -n | tail | sort -nr[/coolcode]
Uniq will discard all but one of successive identical lines from INPUT, writing to OUTPUT. -c (--count) will prefix lines by the number of occurrences.

[coolcode]sort -n | [/coolcode]
Again, sort INPUT but with --numeric-sort enabled. -n compares according to string numerical value.

[coolcode]tail | [/coolcode]
Tail will OUTPUT the last part of the file, default here is tail.

[coolcode]sort -nr[/coolcode]
Finally we sort again, with --numeric-sort and --reverse the result of comparisons.

Thu, Dec 6, 2007 Top 10

[coolcode]
czar@kremlin:~$ history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c | sort -n | tail | sort -nr
116 sudo
114 plb
48 ls
29 cd
26 mpc
22 scp
12 screen
12 rm
10 mc
10 df
[/coolcode]

plb = Playlistbuilder (see Best mpd/mpc scripts

Tags