<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>gHacks Technology News &#124; Latest Tech News, Software And Tutorials &#187; command line tricks</title> <atom:link href="http://www.ghacks.net/tag/command-line-tricks/feed/" rel="self" type="application/rss+xml" /><link>http://www.ghacks.net</link> <description>A technology news blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description> <lastBuildDate>Sat, 11 Feb 2012 17:32:23 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/> <item><title>Search google (and update twitter) from the command line</title><link>http://www.ghacks.net/2009/08/20/search-google-and-update-twitter-from-the-command-line/</link> <comments>http://www.ghacks.net/2009/08/20/search-google-and-update-twitter-from-the-command-line/#comments</comments> <pubDate>Thu, 20 Aug 2009 10:57:27 +0000</pubDate> <dc:creator>Jack Wallen</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[Search Engines]]></category> <category><![CDATA[Tutorials Basic]]></category> <category><![CDATA[command line tricks]]></category> <category><![CDATA[command-line]]></category> <category><![CDATA[curl]]></category> <category><![CDATA[twitter]]></category> <guid
isPermaLink="false">http://www.ghacks.net/?p=15552</guid> <description><![CDATA[There are some of us who prefer to do as much as possible from the command line. For whatever reason, this type of person wants to prove to the world the GUI is not necessary. For that reason, I thought I would illustrate how, with the help of curl, you can search Google and update [...]]]></description> <content:encoded><![CDATA[<p>There are some of us who prefer to do as much as possible from the command line. For whatever reason, this type of person wants to prove to the world the GUI is not necessary. For that reason, I thought I would illustrate how, with the help of curl, you can search Google and update your twitter status from the command line.</p><p>Curl is a tool that transfers data to or from a server. Curl supports HTTP, HTTPS, FTP, FTPS,  SCP,  SFTP,  TFTP,  DICT, TELNET,  LDAP  or  FILE protocols and works without user interaction. But the neat thing about curl is that it offers a ton of various tricks for the clever end user. One of those tricks is fetching and putting data to/from a server &#8211; like Google and Twitter.</p><p><span
id="more-15552"></span><strong>What you&#8217;ll need</strong></p><p>In order to achieve these tasks you will need to have installed both curl and html2text. Since I am showing you how to use these tools for command line tricks, there&#8217;s no need to figure up the GUI tools. So we will install both tools from the command line. To do so you need to open up your terminal and issue a command similar to:</p><p><em>sudo apt-get install curl html2text</em></p><p>You will be prompted for your sudo password and then asked to verify the installation. Hit &#8216;Y&#8217; to continue on with the installation.</p><p>Once these two pieces of software are installed, it&#8217;s time to work some &#8220;magic&#8221;.</p><p><strong>Searching Google</strong></p><p>In order to do this you need to pipe one command through another. Piping is done with the help of the &#8220;|&#8221; character separating the commands. In this case you are going to pipe the curl command through the html2text command. What this will do is render the html fetched from Google into plain text.</p><p>In order to get curl to search a web site you will have to use a single argument with the command. The argument is:</p><p>-A</p><p>which instructs curl to send the user agent string to a web site so the site thinks it is actually a web browser doing the search. Crafty.</p><p>So the command looks like this:</p><p><code>curl -A Mozilla http://www.google.com/search?q='Jack Wallen' |html2text -width 80</code></p><p>Notice I use the single quotes. If you are searching for a single word this is not needed. If there is a space between two words, put them in single quotes. The results from this search would look like:</p><p><code>9. **** My Review of Jack Wallen's Post: �10 Reasons Why Linux Will ... ****<br
/> Windows 7 may be generating some positive buzz, but Jack Wallen remains<br
/> skeptical. In fact, he says it's only a matter of time before Linux takes<br
/> its ...<br
/> techxav.com/.../my-review-of-10-reasons-why-linux-will-triumph-over-<br
/> windows/ -Cached - Similar<br
/> 10. **** Jack Wallen - news ****<br
/> Jack Wallen asks Why aren't schools adopting open source? and the answer<br
/> is simply exposure to open source. Getting thousands of students to call<br
/> and write ...<br
/> www.wikio.co.uk/news/Jack+Wallen -Cached - Similar</code></p><p>Because these results will fly by you might want to do one more trick with this command by sending it to a file instead. To do this we will use the &#8220;&gt;&#8221; character and a file name like so:</p><p><code>curl -A Mozilla http://www.google.com/search?q='Jack Wallen' |html2text -width 80 &gt; search</code></p><p>Once the search is done, issue the command <em>less search</em> and you will see the results of your search.</p><p><strong>Update Twitter status</strong></p><p>The same kind of trick is done with your twitter status. To do this you would issue a command like:</p><p><code>curl -u user:password -d status='Your tweet' http://twitter.com/statuses/update.xml</code></p><p>Where &#8216;Your tweet&#8217; is the status update you want to enter.</p><p>Right after you issue that command a bunch of information will be returned. This information is your profile rendered in XML. I have yet to find a way to turn that off.</p><p><strong>Final thoughts</strong></p><p>The command line is an incredibly powerful tool. Imagine what you can do with these two examples. You could set up a cron job to update your status automatically. Or you could create a script to automatically gather data from Google searches. The possibilites are limitless.</p> ]]></content:encoded> <wfw:commentRss>http://www.ghacks.net/2009/08/20/search-google-and-update-twitter-from-the-command-line/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> </channel> </rss>
