Re:Your top 100 unix commands, for science
by decklin on Sunday May 19, 2013 @01:44PM
(#5733675)
It's ironic that the standard one-liner for this uses a pipeline but only counts the first word of the first command of the pipeline. Given itself as input, "sort" ought to be the most used command, but "history" is the only one counted. (I bring this up not for the sake of standard HN nitpicking but to point out that you probably do want to cover at least `sort` in your workshop, and it will be underrepresented in these results, along with `grep`, `wc`, etc.)
Unfortunately, shell grammar is complex enough that a correct one-liner is probably infeasible. For example, one of my top "commands" if you count by words is an environment variable setting prepended to an actual command.
EDIT: you can get good enough results by just splitting on "|", as others have suggested here -- any parts of regular expressions, etc that aren't really commands will probably be infrequent enough to get lost in the noise, and treating || as containing an empty command won't hurt. If you're going to catch ||, though, might as well get && too... and now you're going down the rabbit hole :-)
Re:Your top 100 unix commands, for science
by ColinWright on Sunday May 19, 2013 @01:50PM
(#5733701)
Quick hack - you can include the commands you pipe to with this:
history \
| sed "s/^[0-9 ]*//" \
| sed "s/ *| */\n/g \
| awk '{print $1}' \
| sort \
| uniq -c \
| sort -rn \
| head -n 100 \
> commands.txt
I haven't tried to account for pipe symbols inside strings - it didn't seem work it.
In case there are commands you want then to exclude (which I do) then you might want to "head -200", remove the commands you don't want to provide, and then trim to 100.
Added in edit - having done this a good half of my top 100 are actually scripts, so this is pretty pointless for me unless I rummage through them to find the common commands.
Added in edit again:
OK, here's a version that only includes actual system commands, and hence filters out all my personal scripts and commands:
history \
| sed "s/^[0-9 ]*//" \
| sed "s/ *| */\n/g" \
| awk '{print $1}' \
| xargs which \
| sed "s.^/usr.." \
| grep ^.bin \
| sed "s/^.*\///" \
| sort \
| uniq -c \
| sort -rn \
> commands.txt
Re:Your top 100 unix commands, for science
by __david__ on Sunday May 19, 2013 @02:46PM
(#5733965)
I think you want s///g on your second sed... Also that doesn't work in Mac OS X for some reason (their sed doesn't appear to interpret \n in the replacement text). I replaced it with perl to make that part work:
perl -pe 's/ *\| */\n/g'
I still haven't gotten the whole thing to work yet because my history contains the above history pipeline and so it's splitting the "|" that inside the sed command onto multiple lines which is causing "xargs which" to balk because quotes are not matching or something:
xargs: unterminated quote
Shells are amazing until spaces or quotes are involved! :-)
Re:Your top 100 unix commands, for science
by jammi on Sunday May 19, 2013 @07:06PM
(#5734796)
Not too difficult to guess what I'm doing. I also use a lot of sed, grep, xargs and such, but they're typically are piped and don't show up here. I removed some local scripts from here that won't make sense to others.
Re:Your top 100 unix commands, for science
by kivikakk on Sunday May 26, 2013 @07:44AM
(#5770849)
"git status -sb" and "git add -p", respectively. Most of the 1-3 letter ones are git aliases (and notice how often I use them!), corresponding to the aliases here: https://github.com/kivikakk/dotdirs/blob/master/gitconfig#L3... (some rubbish in my .zshrc makes it such that "a -> git a")
Re:Your top 100 unix commands, for science
by benmanns on Sunday May 19, 2013 @01:30PM
(#5733622)
Be careful if you are in the habit of using environment variables to specify API keys or database passwords. One of my top commands is `FACEBOOK_SECRET=...`.
Re:Your top 100 unix commands, for science
by m0nastic on Sunday May 19, 2013 @06:41PM
(#5734707)
It might just be my OCD showing, but 'clear' is my number one by an order of magnitude.
next 20:
177 ls
167 cd
122 brew
120 vim
119 cabal
117 cindy (an alias for ssh'ing to my local dev box)
115 sudo
114 tmux
111 man
110 less
110 openssl
109 rm
108 whois
107 ghci
107 lein
106 ssh
86 strings
75 smbclient
75 racket
65 nc
Re:Your top 100 unix commands, for science
by coyotebush on Sunday May 19, 2013 @04:25PM
(#5734264)
My history file is de-duplicated (oh-my-zsh enables hist_ignore_dups), so this sort of approach is never accurate.
Git comes out on top, but presumably because most of my invocations are unique ("git commit -m ..."), while things like "ls" are farther down the list.
Re:Your top 100 unix commands, for science
by bilalq on Monday May 20, 2013 @04:15AM
(#5736507)
Unfortunately, my history settings mess with my results. Commands that are three letters or less just get ignored. Identical commands repeated in succession are also only counted once.
Re:Your top 100 unix commands, for science
by hackerpants on Sunday May 19, 2013 @01:48PM
(#5733692)
Excellent point. I'm definitely going to put that caveat at the beginning of any analysis I post. (and thanks to ctrl_freak for posting an alternative!)
Re:Your top 100 unix commands, for science
by lelandbatey on Sunday May 19, 2013 @04:06PM
(#5734203)
738 ll (alias for a more reformed `ls` output)
549 python
457 cd
397 git
173 exit
157 vim
150 less
142 ssh
122 ./synchVeiled.sh ( script I'd been using a lot for a project )
121 sudo
109 scp
109 fab
101 gca ( alias for "git commit -am" )
97 curl
88 bash
74 grep
68 startx
56 rm
56 lguf ( alias to show all files in a git repo that are not being tracked )
55 history
54 whois
49 htop
48 source
40 echo
39 foreman
Re:Your top 100 unix commands, for science
by jpadvo on Sunday May 19, 2013 @01:20PM
(#5733565)
This would be fantastic if all it had was the instructions to see your own top commands. What a great way to discover opportunities for automation and time saving!
Re:Your top 100 unix commands, for science
by cespare on Monday May 20, 2013 @05:12AM
(#5736679)
Many of my top commands are 1- or 2-letter aliases. g for git, v for vim, and so forth.
I had to change the command slightly to work with zsh -- instead of 'history' I did 'history 1' to get the full (10k entries for me) history instead of the most recent 16.
Re:Your top 100 unix commands, for science
by INTPenis on Sunday May 19, 2013 @02:42PM
(#5733946)
I run wildly different commands on different hosts so I actually took three hosts I'm often logged into and combined their most run commands in history into one 100 line file.
Re:Your top 100 unix commands, for science
by e3pi on Sunday May 19, 2013 @02:57PM
(#5733996)
Super-facile gpm plopping grabs across six nox tty consoles onto emacs and as apps arguments is the most pleasant, productive, and relaxed user interface I know.
Unfortunately, shell grammar is complex enough that a correct one-liner is probably infeasible. For example, one of my top "commands" if you count by words is an environment variable setting prepended to an actual command.
EDIT: you can get good enough results by just splitting on "|", as others have suggested here -- any parts of regular expressions, etc that aren't really commands will probably be infrequent enough to get lost in the noise, and treating || as containing an empty command won't hurt. If you're going to catch ||, though, might as well get && too... and now you're going down the rabbit hole :-)
In case there are commands you want then to exclude (which I do) then you might want to "head -200", remove the commands you don't want to provide, and then trim to 100.
Added in edit - having done this a good half of my top 100 are actually scripts, so this is pretty pointless for me unless I rummage through them to find the common commands.
Added in edit again:
OK, here's a version that only includes actual system commands, and hence filters out all my personal scripts and commands:
Some systems seem to require \r instead of \n - I know vim's behavior differs from sed's in this, so that might be an issue.
With xargs balking, you can throw the error stream at that point, for convert it to a loop over the alleged commands:
Specifically: And yes spaces are a pig, and can lead to all sorts of ambiguities that don't have reasonable ways of resolving them, especially in filenames.history \ | sed "s/^[0-9 ]//" \ | perl -pe 's/ \| */\n/g' \ | gawk '{counts[$1] += 1} END { for (x in counts) { print counts[x],x}}' OFS="\t" \ | column -t \ | sort -k 1,1nr \ | head -100
Ok not sure how to format this on HN https://gist.github.com/nyxwulf/5608955#file-gistfile1-sh
Take the poster's script above and copy it to a text file. Now replace \n with a new line, save and it should run.
Isn't it safer to create a credentials file and give it the appropriate chmod?
http://www.12factor.net/config
112 6725 0.1 36.7 1965924 1411164 ? SLl May03 37:11 /usr/lib/jvm/java-7-openjdk-amd64//bin/java -Xms1g -Xmx1g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Delasticsearch -Des.pidfile=/var/run/elasticsearch.pid -Des.path.home=/usr/share/elasticsearch -cp :/usr/share/elasticsearch/lib/elasticsearch-0.90.0.jar:/usr/share/elasticsearch/lib/:/usr/share/elasticsearch/lib/sigar/ -Des.default.config=/etc/elasticsearch/elasticsearch.yml -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=/etc/elasticsearch org.elasticsearch.bootstrap.ElasticSearch
next 20:
Git comes out on top, but presumably because most of my invocations are unique ("git commit -m ..."), while things like "ls" are farther down the list.
Relevant: https://github.com/paulmars/huffshell
They work on teaching scientists to be better at software, and are always looking for people to do workshops
Edit:
works for me.I can't wait for the full results.
I'll also post the results to HN, of course :)
d <foo> is short for {cd <foo>;ls}. l is ls. m is mv. o is Apple's open command. e is emacsclient.
The only reason grep is not in that list is that I do my grepping through an emacs command (M-x grep).
pwd is frequent because I do not put the working directory in my shell prompt.
I had to change the command slightly to work with zsh -- instead of 'history' I did 'history 1' to get the full (10k entries for me) history instead of the most recent 16.
Fun project, good luck!
I had to use
history | sed "s/^[0-9 ]//" | sed "s/ | */\n/g" | awk '{print $3}' | sort | uniq -c | sort -rn | head -n 100 > commands.txt
I suppose you could guess that my Linux box is an LNMP server pretty easily.
I guess the future is all about regular expressions :)
`history -100`
on OS X, anyway, the default only gives 15 or so commands in history
I use the awkscript below to compact it:
# histsort.awk --- compact a shell history file # Thanks to Byron Rakitzis for the general idea
702 ls
623 cd
618 gs
349 mate
340 ga
313 bundle
251 rake
221 ssh
197 gd
164 cat
159 grep
153 rm
148 rails
131 cap
127 gem
125 exit
122 powder
109 vagrant
98 vim
67 rbenv
66 make
65 zeus
65 ping
63 cp
61 gco
58 mv
55 sudo
51 ps
47 mkdir
43 kill
37 grm
36 echo
33 ruby
30 foreman
29 gdb
26 brew
188 jobs
113 grep
74 git
72 ls
72 cd
53 vi
clearly no one else uses vim like i do.