Unshorten URL

Unshorten.net is a tool designed to expand or reveal the original, full-length URL behind a shortened URL

Unshorten URL with Command Line: Best Tools & Scripts for Developers


Shortened URLs have become an integral part of the web. Platforms like ShortenWorld, Bitly, TinyURL, Rebrandly, and Shorter.me are widely used to compress long links into compact, shareable formats. These shortened links make it easy to share content in emails, social media posts, QR codes, and messaging apps.

But for developers, cybersecurity researchers, and IT administrators, shortened URLs can pose significant challenges:

  • Security risks: Shortened links can mask malicious websites, phishing pages, or malware downloads.
  • Transparency issues: Developers and end-users often want to know where a link leads before clicking it.
  • Automation needs: In large-scale workflows, developers may need to unshorten hundreds or thousands of URLs automatically.

This is where command-line tools for unshortening URLs come into play. These tools allow developers to expand shortened URLs safely, efficiently, and in a way that integrates seamlessly into scripts, automation pipelines, and security analysis tools.

In this article, we’ll cover:

  • Why developers need command-line tools for unshortening links.
  • How URL shortening and unshortening work technically.
  • The best CLI tools and libraries available for unshortening.
  • Step-by-step guides with examples in cURL, Python, Node.js, and Bash.
  • Advanced automation workflows for bulk unshortening.
  • Security and ethical considerations when unshortening links.

By the end, you’ll have a complete understanding of how to handle URL unshortening at the command line level — and how to choose the right tools for your development projects.


Why Developers Need Command-Line Tools for Unshortening URLs

While non-technical users can rely on web-based unshortening tools (like Unshorten.net or CheckShortURL), developers often prefer command-line tools for several reasons:

1. Automation at Scale

Imagine you are processing millions of shortened URLs from social media feeds, emails, or logs. A web-based service won’t cut it. CLI tools allow you to integrate unshortening directly into scripts, cron jobs, or CI/CD pipelines.

2. Security Analysis

Cybersecurity teams often investigate phishing campaigns that rely heavily on shortened URLs. Being able to batch-unshorten these links helps analysts quickly determine which destinations are safe or malicious.

3. Integration with Existing Tools

Command-line utilities can be combined with other Unix tools (grep, awk, sed) or integrated into data pipelines (e.g., using Fluentd, Logstash, or Kubernetes logging).

4. Cross-Platform and Lightweight

CLI tools work on Linux, macOS, and even Windows (via WSL or PowerShell). They don’t require a heavy GUI, making them lightweight for servers or cloud environments.


How URL Shortening and Unshortening Works

Before diving into tools, let’s understand what happens under the hood when a shortened URL is created or unshortened.

1. Shortening

  • A service like ShortenWorld maps a long URL (e.g., https://example.com/article?id=12345&ref=abc) to a short alias (https://ln.run/3xyz9).
  • This mapping is stored in the service’s database.

2. Redirection

When you visit the shortened link:

  • The browser sends an HTTP request to the shortening service.
  • The service responds with an HTTP redirect status code (301 or 302), pointing to the original URL.
  • The browser follows the redirect and lands on the destination page.

3. Unshortening

Unshortening is the reverse process. CLI tools (like curl) send an HTTP request but instead of stopping at the first response, they follow redirects until reaching the final destination URL.

For example:

curl -I https://ln.run/3xyz9

might return:

HTTP/1.1 301 Moved Permanently
Location: https://example.com/article?id=12345&ref=abc

That Location header is the unshortened URL.


Best Command-Line Tools for Unshortening URLs

There are several tools developers can use at the command line to expand shortened links. Let’s explore the most popular ones.

1. cURL

The most versatile and widely available command-line tool for working with URLs.

  • Available by default on most Linux and macOS systems.
  • Can follow redirects automatically with the -L flag.
  • Supports scripting and integration with other commands.

Example:

curl -Ls -o /dev/null -w %{url_effective} https://ln.run/3xyz9

This prints the final destination URL.


2. Wget

Another standard tool for downloading web content.

  • Available on Linux and Windows.
  • Follows redirects with the --max-redirect option.

Example:

wget --max-redirect=10 --server-response --spider https://tinyurl.com/abcd

This shows each redirect step until the final URL.


3. Uncurl / ExpandURL Scripts

Custom shell scripts exist that wrap around curl to simplify unshortening.

Example unshorten.sh:

#!/bin/bash
curl -Ls -o /dev/null -w %{url_effective} "$1"

Usage:

./unshorten.sh https://t.co/abcd

4. Python Requests (CLI or Scripted)

Python developers can use the requests library.

Example Script:

import requests

def unshorten(url):
    response = requests.head(url, allow_redirects=True)
    return response.url

print(unshorten("https://ln.run/3xyz9"))

You can run this in the terminal or wrap it in a CLI tool using argparse.


5. Node.js (Axios / Got)

JavaScript developers can build unshorteners with axios or got.

Example:

import axios from "axios";

async function unshorten(url) {
  const response = await axios.get(url, { maxRedirects: 10 });
  console.log(response.request.res.responseUrl);
}

unshorten("https://ln.run/3xyz9");

Run it via Node in the command line.


6. Go-based Tools

Go binaries are fast and portable. Developers often publish small Go utilities for unshortening.

Example (pseudo Go code):

resp, err := http.Get("https://tinyurl.com/abcd")
fmt.Println(resp.Request.URL.String())

Compile once, and you have a single binary to use across platforms.


7. Third-Party CLI Tools

  • url-expander (npm) – Node-based CLI tool.
  • unshorten (PyPI) – Python CLI utility.
  • httpie – More human-friendly than curl, supports redirect tracing.

Example:

http --follow https://ln.run/3xyz9

Step-by-Step Examples: Unshortening with CLI Tools

Let’s go through practical workflows.

Using cURL for Single URL

curl -Ls -o /dev/null -w %{url_effective} https://ln.run/3xyz9

Using cURL for Multiple URLs

while read url; do
  echo "$url -> $(curl -Ls -o /dev/null -w %{url_effective} $url)"
done < urls.txt

This processes each shortened URL from urls.txt.


Using Python for Bulk Unshortening

import requests

with open("urls.txt") as f:
    urls = f.read().splitlines()

for url in urls:
    try:
        r = requests.head(url, allow_redirects=True, timeout=5)
        print(f"{url} -> {r.url}")
    except Exception as e:
        print(f"{url} -> ERROR: {e}")

Using Bash + Wget

for url in $(cat urls.txt); do
  wget --max-redirect=10 --spider --server-response "$url" 2>&1 | grep "Location"
done

Using Node.js

import axios from "axios";
import fs from "fs";

async function expand(url) {
  try {
    const res = await axios.get(url, { maxRedirects: 10 });
    console.log(` -> `);
  } catch (e) {
    console.error(` -> ERROR`);
  }
}

const urls = fs.readFileSync("urls.txt", "utf-8").split("\n");
urls.forEach(expand);

Advanced Workflows for Developers

1. Integration with Log Analysis

If you have logs containing shortened URLs:

grep -o 'http[s]*://ln.run/[a-zA-Z0-9]*' access.log | sort | uniq > urls.txt

Then unshorten them in bulk with your preferred method.


2. Unshortening Inside CI/CD Pipelines

  • Check all URLs in your documentation or release notes.
  • Automatically expand them to verify they aren’t broken.

Example GitHub Action:

- name: Check shortened links
  run: |
    for url in $(cat urls.txt); do
      curl -Ls -o /dev/null -w "%{http_code} %{url_effective}\n" $url
    done

3. Security Analysis Workflow

  • Extract shortened links from phishing emails.
  • Bulk unshorten them.
  • Pass expanded URLs to threat intelligence APIs (like VirusTotal).

4. Using Docker for Portability

Create a containerized unshortener:

FROM python:3.12-slim
RUN pip install requests
COPY unshorten.py /usr/local/bin/unshorten.py
ENTRYPOINT ["python", "/usr/local/bin/unshorten.py"]

Run anywhere with:

docker run --rm my-unshortener https://ln.run/3xyz9

Security and Ethical Considerations

While unshortening is powerful, developers should use it responsibly.

  • Avoid accidental DDoS: Don’t hammer shortening services with millions of requests at once. Use rate limiting.
  • Respect privacy: Some shortened links may contain private tokens or personal data. Don’t log sensitive information.
  • Detect malicious redirects: Not all expanded URLs are safe. Always scan final destinations against malware databases.
  • Use HEAD instead of GET: When possible, use HEAD requests to avoid downloading full content.

Pros and Cons of Command-Line URL Unshortening

Pros

  • Fast and scriptable.
  • Works at scale.
  • Cross-platform.
  • Integrates with automation workflows.

Cons

  • Requires technical knowledge.
  • Some services block bots or automated requests.
  • Not all links expand cleanly (some use JavaScript-based redirects).
  • Risk of contacting malicious servers.

Future of URL Unshortening in Developer Workflows

With increasing concerns around phishing, tracking, and transparency, developers are likely to see more demand for automated unshortening tools. Future trends include:

  • AI-powered link safety checks – Expanding URLs and classifying them automatically.
  • Browserless detection – Handling JavaScript redirects with headless browsers (Puppeteer, Playwright).
  • Cloud-based APIs – Offering scalable URL expansion with integrated security checks.
  • Integration into SIEM systems – Security tools embedding automatic unshortening.

Conclusion

Unshortening URLs with the command line isn’t just a neat trick — it’s an essential capability for developers, security researchers, and system administrators. With tools like cURL, Wget, Python requests, Node.js Axios, and Go utilities, you can safely and efficiently expand shortened links at scale.

Whether you’re investigating phishing campaigns, validating marketing links, or automating pipelines, CLI unshortening provides the flexibility and transparency developers need.

By integrating these workflows into your toolset, you not only save time but also improve security, reliability, and automation in your projects.