Favorite Commandline Hack
One of my favorite commandline hacks is demonstrated by the following example:
history | gawk -F ' ' '{print $2}' | sort | uniq -c | sort -nr | more
What this does is takes a text file (or history of the commands used in our case), chops it to print the right field, sorts and counts the number of times a particular term occurs. For example here are the top commands I have used on this server:
373 ls
268 cd
42 more
29 ps
27 rm
25 du
24 ./bin/startup.sh
22 exit
17 source
15 emacs
14 sudo
13 ssh
This is immensely useful and a quick way to do anything from process a huge file, count the number of times a link occurs, word counting and all sorts of processing that come up frequently in large social media datasets. Its a really easy way to do some mundane tasks without having to write a script or much code for it. So what are your favorite commandline hacks? share the joy! :-)


Comments