Curl to exapnd short url

2022-01-09 105 words 1 min read

Many times I receive short urls in mail and other places like chats and messages. I first like to see the destination before I click on the url. I was looking for some way to do this in bash. I realized that this could be very simply done by looking at the Location header in the response from curl.

Example

1
curl -I https://bit.ly/32WwCp4|grep location

and the output should be something like

1
location: http://blog.amit-agarwal.co.in/

and if you would like to simplify this, then you can use the following

1
curl -I https://bit.ly/32WwCp4 2>&1 |awk '/location/{print $2}'

and this will print only the final url.


Tags: Learning bash

Related Articles:


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it