Theodore Baschak

Routing Guru. IPv6 Advocate. Operator of Hextet Systems (AS395089).

Unshortening with cURL

Tue, 12 Aug 2014 21:47:34 -0500 » Nerd Projects, Networking, CLI, System Administration, Network Monitoring » Estimated read time: 1 min

Sometimes you get a short URL for something and would like to know where it goes before clicking on it. cURL can help you determine this. This can be done with the following one-liner.

curl -s -o /dev/null -I -w "%{url_effective}\n" -L $URL

This can be adapted into a simple, small shell script which gives the user a usage/help when 1 argument isn’t given.

unshorten.shlink
#!/bin/bash
function usage ()
{
echo "Usage:";echo " $0 <url>"
}
if [ $# -ne 1 ]; then </div></div>
</span>usage;exit 127
fi </div></div>
</span>
curl -s -o /dev/null --head -w "%{url_effective}\n" -L "$1"
</pre></div></figure>