News for hackers. Stuff that matters.

Quick and easy search for linux command-line examples

I love http://commandlinefu.com. While doing my once-a-week search for interesting command-line chops the other day I discovered they have a simple search API. I thought it would be useful to integrate this into my bash shell so I could quickly pull up examples of useful linux commands.

Here is what I came up with. Basically I bind ctrl-u in bash to prompt me for a search term, then I use curl to search commandlinefu.com via their plaintext API.

Paste this into your .bash_profile

function doCLFSearch { echo -n "search http://commandlinefu.com for: " read SEARCHTERM URL_ENC_ST=`php -r "echo rawurlencode('$SEARCHTERM');"` ENCODED=`echo -n $SEARCHTERM | openssl enc -base64` curl -s "http://www.commandlinefu.com/commands/matching/$URL_ENC_ST/$ENCODED/plaintext" | less -p "$SEARCHTERM" }

bind '"\C-u"':"\"doCLFSearch\C-m\""

source .bash_profile

Then hit ctrl-u and search away!

Enjoy.

CP

( 2 comments | 8 points | on HN )
Re:Quick and easy search for linux command-line examples by gnosis on Sunday February 20, 2011 @07:32PM (#2243662)
Would it be possible for you to repost this with proper indentation?

To make HN preserve the indentation of your code, just preface each line with two spaces. Thanks!

Re:Quick and easy search for linux command-line examples by zuu on Sunday February 20, 2011 @07:48PM (#2243710)
That's pretty handy