One of the tasks I like to do is look for tips or useful things to do with Bash.
I just found it on the blog of 4D43 a tip that allows you to do just what I say in the title, shorten a URL with a command.
Shorten urls? … Yep. For example, a URL like https://blog.desdelinux.net/acortar-urls-con-un-comando-en-linux-bash/ it has many letters, however that shortened URL would be: http://is.gd/NMiTwF
Well, I'll show you how to shorten by using the http://is.gd
First we need the package xsell installed, which is who will allow us to take the URL that we copy and use it in the terminal.
To install it on Debian, Ubuntu or derived:
sudo apt-get install xsel
Once installed, we put this in a terminal:
curl -s "http://is.gd/create.php?format=simple&url=`xsel -po`"
Once this is done, the short URL will appear.
I mean ... I explain again.
- We copy the long URL that we want to cut.
- We write in the terminal the command that I put them above.
- We press [Enter] and it will show you the cut URL.
I leave you a screenshot:
As you can see it shows ... but, if what we want is to put it on the clipboard directly, that is ... if we want that when executing the command we already have the short link saved, and to use it it is only to paste it ([Ctrl] + [V]) we execute this other:
curl -s "http://is.gd/create.php?format=simple&url=`xsel -po`" | xsel -pi
This more than anything is a curiosity, but it could be useful for a script that we are doing hehe ...
Thank you very much to 4d43 for sharing the tip 😀
regards
It is a very good tip and can be very useful. To make things easier for us, we can create an alias in bashrc with the 'curl….' Then you do not have to remember such a command .. We simply copy the link to shorten, enter the alias and that's it
Yes, an alias like "shorten" would not be bad, let's see if I finish some tests and put how to do it with Goo.gl authenticating with the Google account of each one, that would be great 😀
This is my Alias line, done and tested before issuing my comment:
alias shorten = 'curl -s «http://is.gd/create.php?format=simple&url=`xsel -po`»'
You have inspired me, I will do something to send tweets through the terminal from windows, that will be today's project 🙂
HAHAHAHA man, that would be GREAT 😀
Does anyone know how to do it with goo.gl?