It's a typical Wednesday morning for me. I had successfully made my way onto the train and I'm just sat there gazing out the window. That's when it struck me. I wonder what my most frequently used commands are.

After getting into the office, and grabbing some much needed caffeine, I pulled out this good ol' history command to see my top 10 most used commands.

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10

Here's the findings from my local box (preface: I purge my history every 2 weeks)

1 186 37.2% git

2 86 17.2% vagrant

3 50 10% ls

4 39 7.8% ssh

5 33 6.6% cd

6 24 4.8% pwd

7 10 2% clear

8 8 1.6% rm

9 7 1.4% curl

10 5 1% vi

The results were no real surprise to me since I haven't done anything other than git and vagrant these last two weeks. I was surprised to see I utilize ssh so much.. I figured I'd take a quick peek and see why I use it so much. I'm not going to post my history for ssh as I'd rather not expose all that info to you fine folks :) :)

Advertisement

*I toodle off and do the history searching of ssh*

After taking a look at my ssh history, I was pleasantly surprised that I use SSH tunnels waaay too much. More than likely, I'm typing the whole SSH tunnel syntax every time. In case you're wondering what that is.. it's as simple as

ssh -L <localport>:<destination_server>:<destination_port> <your jump box>

I figured I may as well try and make this a lot simpler. This is where I remembered my good buddy alias

Advertisement

I whipped together this quick alias that will let me supply 3 arguments: Local_port, destination_port, destination_server.

alias tunnel='function __tunnel() { ssh -L $1:$3:$2 my_jump_box; unset -f __tunnel;}; __tunnel'

I substituted my actual jump box out of the alias. This makes things super simple for when I need to whip up an ssh tunnel. All I do now is

tunnel 9000 443 blah.blah

This'll setup an SSH tunnel to blah.blah over local port 9000 to destination port 443 via the configured jump box in my alias.

Advertisement

Super!

Let me know if you have a simpler way of doing this!