trurl: A new command-line tool for URL parsing and manipulation by cURL Developer

A new command line tool trurl (tr stands for translate or transpose) has been recently released by Daniel Stenberg, the developer of cURL.

This tool makes working with URLs in shell scripts easier to parse URLs and address security problems associated with them while working with shell scripts.

⛏️ trurl stands for "translate or transpose URLs"

One of the great things about trurl is that it uses the libcurl URL parser, so it understands URLs in the same way that cURL, the popular command line tool, does. This makes it the perfect companion tool for curl users who want to parse and manipulate URLs more efficiently.

trurl is more than just a URL parser. It also helps to solve the many security problems associated with working with URLs. With trurl, you can feel confident that you're working with URLs safely and securely.

How to pronounce trurl? It's simple – just say "trurel", as if an 'e' existed between the r and l at the end.

How to install trrul

    If you are on the Mac (macOS) or Linux (Ubuntu or other distributions) you can make use of homebrew package manager.

    Installation Command:
    brew install trurl

trurl Examples

  • man command

    % man trurl
    trurl(1)                                     trurl Manual                                     trurl(1)
           trurl - transpose URLs
           trurl [options]
           trurl parses, manipulates and outputs URLs and parts of URLs.
           It uses the RFC 3986 definition of URLs and it uses libcurl's URL parser to do so, which
           includes a few "extensions".
           Typically you set a few inputs and decide what of that you want output.

  • To know the version

    % trurl --version
    trurl version 0.2 libcurl/7.86.0

  • Create a URL using --set option

    % trurl --set --set scheme=http
    % trurl --set --set scheme=ftp
    % trurl --set --set scheme=smtp

    Use -s or --set to set the URL component. Note: Setting blank string ("") will clear it from the URL.

    trurl command set example

  • Change PORT of a URL

    % trurl --url --set port=8090

    --url option: To set the input URL to work with.

    trurl command change port number

  • Replace the host name of a URL

    % trurl --url --set

  • Extract the path from a URL

    % trurl --url --get '{path}'
    trurl extract path of a URL

  • Append to a path of a URL

    trurl --url --append path=2023

  • Append a query string to a URL

    % trurl --url "" --append query=year=2023

  • Read URLs from stdin (Example: A file)

    cat urls.txt | trurl --url-file -

    Make use of -f or --url-file to read URLs from the given file. Use the file name "-" to let trurl read the URLs from stdin.

  • Output JSON for a URL

    Use --json flag to output all components of the URL as a JSON object.

  • trurl "" --json
      "url": "",
      "scheme": "https",
      "host": "",
      "port": "443",
      "path": "/tools/java",
      "query": "year=2023&topic=java20",
    trurl JSON Output

References & Related Articles:

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap