Loading...

How to convert a long link to a short url on Linux CLI

Link shorten Linux

URL shortening is a popular technique used to transform long, cumbersome URLs into shorter, more manageable ones. It helps to improve readability, shareability, and usability in various contexts, such as social media platforms or messaging apps. In this article, we will explore how to shorten URLs on Linux distributions like CentOS, Debian, RedHat, and Ubuntu using a simple cURL command.

Step 1: Install cURL (if necessary):

Before we proceed, ensure that cURL is installed on your Linux distribution. Most modern Linux distributions come with cURL pre-installed, but if it’s not available, you can install it using the package manager specific to your distribution. Here are the commands to install cURL on popular distributions:

On CentOS/RHEL:

root@guadeloupe:~# sudo yum install curl

On Debian/Ubuntu:

root@guadeloupe:~# sudo apt install curl

Step 2: Generate a Shortened URL:

To shorten a URL using cURL, we will utilize the free URL shortening service provided by « la.gp. » Follow the steps below:

  1. Open a terminal on your Linux distribution.
  2. Type the following command, replacing « [URL] » with the actual URL you want to shorten:
curl -s "https://la.gp/en/api/free?url=[URL]" && echo -e "\n"

For example, if you want to shorten the URL « https://www.youtube.com/watch?v=RZopVeN8j-U, » the command would be:

curl -s "https://la.gp/en/api/free?url=https://www.youtube.com/watch?v=RZopVeN8j-U" && echo -e "\n"

Press Enter to execute the command.

Step 3: Obtaining the Shortened URL:

After executing the command, cURL will send a request to the « la.gp » API and retrieve the shortened URL for you. The response will be displayed in the terminal window.

Example Output:

Copy the shortened URL from the terminal output and use it as needed.

Shortening URLs on Linux distributions like CentOS, Debian, RedHat, and Ubuntu can be accomplished quickly and easily using the cURL command-line tool. By leveraging the « la.gp » API, you can generate shortened URLs that are more user-friendly and easier to share. Remember to replace « [URL] » with the actual URL you want to shorten in the cURL command. Now you can streamline your long URLs and improve their accessibility in various online platforms.

2 commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *