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 ;)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: , , ,

Sunday, February 22nd, 2009 Command Line

Leave a Reply

my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
February 2009
S M T W T F S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.