Curl to exapnd short url

2022-01-09 1 min read Learning bash

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.

comments powered by Disqus