
If you’ve ever touched a command line, you’ve probably met curl.
It’s the trusty Swiss Army knife we all reach for to download files, test API endpoints, or just check if a website is online.
We often use it like this:
curl <https://api.github.com>
And poof! A giant blob of text floods our screen. We squint, scroll, and try to find the one piece of information we actually need.
It gets the job done, but it feels a bit like using a fire hose to water a houseplant.
But what if I told you that curl was never meant to be a solo artist? Its true power is unlocked when it teams up with other commands. Think of curl as the lead guitarist of a rock band. It’s great on its own, but when the drummer, bassist, and vocalist join in, you get magic.
Today, we’re going to introduce you to curl‘s bandmates—the commands that turn simple output into a powerful, automated workflow.
Table of Contents
First, a Quick Intro to the Magic Pipe |
Before we meet the band, we need to understand how they connect. In the world of Linux and macOS, this connection is a single character: the pipe (|).
The pipe does exactly what it sounds like. It takes the output from the command on its left and “pipes” it directly as the input to the command on its right.
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
Command A | Command B
It’s a simple but profound concept. It lets us chain commands together, with each one performing a specific task, to build something far more powerful than the sum of its parts.
Now, let’s meet the partners.
Partner #1: jq — The JSON Whisperer
If curl has a best friend, it’s jq. In today’s world, almost every API responds with data in JSON format. While JSON is great for machines, it’s a nightmare for humans to read directly in the terminal.
jq is a lightweight command-line tool that parses, filters, and transforms JSON data with incredible ease.
Let’s see it in action. Imagine you want to find the URL for Linus Torvalds’ very first GitHub repository.
First, the “lonely” curl way:
curl <https://api.github.com/users/torvalds/repos>
You get a massive wall of text. Good luck finding what you need.
Now, let’s bring in jq.
# The -s flag tells curl to be silent, hiding the progress bar.
# This is crucial for clean piping!
curl -s "<https://api.github.com/users/torvalds/repos>" | jq '.[0].clone_url'
And just like that, you get a clean, simple answer:
"<https://github.com/torvalds/libdc-for-dorks.git>"
What happened here?
curl -sdownloaded the data silently.- The pipe (
|) sent that massive JSON blob over tojq. jq '.[0].clone_url'toldjqexactly what to do: “In this data, find the first item in the array (.[0]) and give me the value of itsclone_urlfield.”
It’s clean, precise, and repeatable. For anyone working with APIs, curl and jq are an essential duo.
Partner #2: grep — The Text Detective
So, jq has our back for structured data. But what about messy, unstructured text, like HTML pages or log files?
That’s where our next partner shines. grep is a classic tool that scans text and prints any lines that contain a specific pattern.
Let’s say you want to quickly check if a website is trying to set any cookies in its response headers.
# The -I flag tells curl to only fetch the headers.
# The -i flag on grep makes the search case-insensitive.
curl -sI "https.medium.com" | grep -i 'set-cookie'
The output will instantly show you only the lines you care about:
set-cookie: uid=...; expires=...; path=/; domain=.medium.com
set-cookie: sid=...; expires=...; path=/; domain=.medium.com
...
No more scrolling through dozens of header lines. curl grabs the data, and grep acts as your personal detective, finding the exact clues you asked for.
Partner #3: bash — The Dangerous Executor
This next partner is incredibly powerful, but you must treat it with extreme caution. You can pipe curl’s output directly into bash (or any shell) to download and execute a script in one go.
You’ve probably seen this pattern used in installation guides:
# This is an EXAMPLE. Do not run random scripts from the internet!
curl -sSL <https://install.example.com/setup.sh> | bash
A Big, Loud Security Warning: Running this command gives the setup.sh script complete control over your system. It can install software, delete files, or do anything else it’s programmed to do. Never, ever run a script from a source you do not fully trust.
A much safer approach is to download the script first, review its contents, and then run it.
# Step 1: Download the script
curl -o setup.sh <https://install.example.com/setup.sh>
# Step 2: Review the script's contents. Make sure it's safe!
less setup.sh
# Step 3: If you trust it, then run it.
bash setup.sh
Partner #4: xargs — The Task Master
Sometimes, curl gives you a list of things, like a list of URLs. What if you want to perform an action on each item in that list?
That’s a job for xargs. It’s a clever utility that takes input from the pipe and uses it to build and execute new commands.
Imagine you have a file named images.txt with a list of image URLs, and you want to download them all.
images.txt:
<https://images.unsplash.com/photo-1.jpg>
<https://images.unsplash.com/photo-2.jpg>
<https://images.unsplash.com/photo-3.jpg>
Here’s how xargs helps curl get the job done:
cat images.txt | xargs -n 1 curl -O
How does this magic work?
cat images.txtreads the file and pipes the list of URLs.xargs -n 1receives the list and says, “Okay, I’m going to take each line, one at a time (n 1).”- For each line, it runs the
curl -Ocommand, pasting the URL at the end.Otellscurlto save the file with its original name.
It effectively runs these commands for you, one after another: curl -O <https://images.unsplash.com/photo-1.jpg curl -O <https://images.unsplash.com/photo-2.jpg … and so on.
A Final Pro-Tip for Clean Pipelines
To make sure curl plays nicely with its partners, always remember these flags:
sor-silent: Hides the progress meter. This is essential for clean output.for-fail: If the server returns an error (like a 404),curlwill fail silently instead of outputting the error page. This prevents bad data from flowing down your pipe.Lor-location: If a URL is a redirect,curlwill automatically follow it to the new location.
Conclusion
curl is more than just a tool for downloading things. It’s a citizen of a rich command-line ecosystem.
By learning to connect it with partners like jq, grep, and xargs, you transform it from a simple utility into a cornerstone of powerful automation.
So next time you open your terminal, don’t let curl work alone. Introduce it to its friends, build a pipeline, and watch the magic happen.



