A Bash Script To Decode TinyURLs
This is a simple bash script, intended to decode tinyurl URLs, i.e. to revret a tinyurl into the original URL.
It’s always a good practice checking where a URL will send you to before actually visiting it.
For the implementation, I the “Preview” service supplied by tinyurl themselves.
The script is short so I won’t bother explaining it. If you have questions please feel free to comment.
We’ll call the script: deurl (stands for: Decode URL). You might rename it as you want
It gets as its first argument the url you want to decode. It can be the complete URL, or just the “unique” part. All these are legal inputs:
http://tinyurl.com/d5j5b7
http://www.tinyurl.com/d5j5b7
tinyurl.com/d5j5b7
d5j5b7
etc..
so you can call the script, for example, like this:
deurl d5j5b7
And you’ll get output similar to this:
http://amirwatad.com
Here is the code:
Add this into a new text file:
1
2
3
4
5 #!/bin/bash
url=$*
url=`echo "$url" | sed -e 's/.*tinyurl.com\///'`
url="preview.tinyurl.com/"$url
wget -O - $url 2> /dev/null | grep redirecturl | sed -e 's/.*href=\"//g' | sed -e 's/">.*//g'
Now, save the file as deurl.
Make the file executable:
chmod +x deurl
Move the file to /usr/local/bin (optionally).
That’s it. Now you can use it as explained above.
Enjoy
No related posts.
Leave a Reply
About Me
Tags
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)
