Master cURL on Linux: Essential Commands for Downloading, Uploading, and More

This guide walks you through practical cURL commands on Linux, covering file downloads, redirects, resume support, timeout settings, form submissions, email handling, and key differences from wget, all illustrated with clear examples and screenshots.

21CTO
21CTO
21CTO
Master cURL on Linux: Essential Commands for Downloading, Uploading, and More

Introduction

cURL (client URL) is a versatile transfer tool on Linux that can upload and download files, often used to verify URL accessibility. Compared with wget, cURL offers more customizable request parameters, making it superior for simulating web requests, while wget excels at FTP and recursive downloads.

What is cURL

cURL interacts with websites or APIs, sending requests and receiving responses or saving data to files. It can be part of scripts to fetch data for further processing. Although cURL is smooth for downloading, tools like wget may be preferable for certain tasks.

Downloading Files

The most basic cURL command downloads a web page or file using HTTP by default. curl https://www.21cto.com Adding the --output option saves the content to a file: curl www.21cto.com --output 21cto.html For binary files such as Word documents, cURL streams the data in binary form and saves it to the current working directory.

Redirects

When a URL redirects, cURL does not follow by default. Use the -L option to follow redirects:

curl -L www.21cto.com

Resuming Downloads

If a download is interrupted, cURL can resume with the -C - option:

curl -C - 21cto.com/some-file.zip --output myfile.zip

Setting Timeouts

Use -m to set a maximum execution time (in seconds): curl -m 60 21cto.com Or use --connect-timeout to limit connection establishment time:

curl --connect-timeout 60 21cto.com

Form Submission

POST data with -d:

curl -d 'name=user&gender=male' https://sso.21cto.com

Upload a file as POST data: curl -d @file-name https://sso.21cto.com Upload a file to an FTP server:

curl -T myfile.txt ftp://ftp.21cto.com/uploads/misc/

Sending Emails

cURL can send emails via SMTP:

curl smtp://mail.example.com --mail-from [email protected] --mail-rcpt [email protected]

The email body must be provided in a file (e.g., email.txt) with standard headers and content.

Reading Emails

cURL supports IMAP and POP3 to read mail. Example using IMAP:

curl -u username:password imap://mail.imapmail.com

To fetch a specific message, use the -X option with UID:

curl -u username:password imap://mail.imapmail.com -X 'UID FETCH 1234'

Differences Between cURL and wget

Both can download content, but wget excels at recursive site downloads and FTP, while cURL is better for uploading files and fine‑grained request customization.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxHTTPFile Downloadcommand-linecURL
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.