Shorten URLs with a command (Bash)

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.

  1. We copy the long URL that we want to cut.
  2. We write in the terminal the command that I put them above.
  3. 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


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Leper_Ivan said

    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

    1.    KZKG ^ Gaara said

      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 😀

      1.    Leper_Ivan said

        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`»'

  2.   v3on said

    You have inspired me, I will do something to send tweets through the terminal from windows, that will be today's project 🙂

    1.    KZKG ^ Gaara said

      HAHAHAHA man, that would be GREAT 😀

  3.   snack said

    Does anyone know how to do it with goo.gl?