curl Command in Linux with Examples - GeeksforGeeks (2025)

Last Updated : 22 Apr, 2025

Comments

Improve

curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.

Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed directly from the terminal — no need to fire up a browser or install some slick app.

Syntax of curl Command

curl [options] [URL]

Here,

  • [options]: Can be various command-line flags that modify the behavior of curl
  • [URL]: Specifies the location from which to fetch or send data.

Why is curl So Popular in Linux?

  • It's installed by default on the majority of Linux distros such as Ubuntu, Debian, CentOS, etc.
  • It handles an enormous set of protocols such as HTTP, HTTPS, FTP, and many more.
  • You can utilize it to download files, upload files, make API calls, and even debug web applications.
  • It's scriptable – excellent for automation and cron jobs.
  • Lightweight and quick — launches in seconds.

Fetching Data Using curl Command

One of the most common use cases of `curl` is fetching data from a URL. This could be a simple HTML page, a file, or any resource accessible via a URL. To fetch a web page using `curl`, you simply provide the URL as an argument:

curl https://example.com
curl Command in Linux with Examples - GeeksforGeeks (1)

This command will retrieve the HTML content of the specified URL and display it in the terminal.

curl https://www.geeksforgeeks.org

This should display the content of the URL on the terminal. The URL syntax is protocol dependent and multiple URLs can be written as sets like:

curl http://site.{one, two, three}.com

URLs with numeric sequence series can be written as:

curl ftp://ftp.example.com/file[1-20].jpeg

Progress Meter: curl displays a progress meter during use to indicate the transfer rate, amount of data transferred, time left, etc.

curl -# -O ftp://ftp.example.com/file.zip
curl --silent ftp://ftp.example.com/file.zip

If you like a progress bar instead of a meter, you can use the -# option as in the example above, or --silent if you want to disable it completely.

Example:

curl Command in Linux with Examples - GeeksforGeeks (2)

Handling HTTP Requests Using curl Command

The `curl` command allows you to send custom HTTP requests with various methods such as GET, POST, PUT, DELETE, etc. For example, to send a GET request:

curl -X GET https://api.sampleapis.com/coffee/hot
curl Command in Linux with Examples - GeeksforGeeks (3)

In the same way, to send a POST request with data:

curl -X POST -d "key1=value1&key2=value2" https://api.sampleapis.com/coffee/hot

In this case, the `-d` flag is used to send data to be sent with the request.

Downloading Files Using curl Command

curl is also generally used to download a file from the web. To download a file, you simply provide the URL of the file as the argument:

-o: saves the downloaded file to the local host with the specified name in parameters.

Syntax:

curl -o [file_name] [URL...]

Example:

curl -o hello.zip ftp://speedtest.tele2.net/1MB.zip

Output:

curl Command in Linux with Examples - GeeksforGeeks (4)

The above example downloads the file from the FTP server and saves it with the name hello.zip.

-O: This option downloads the file and saves it with the same name as in the URL.
Syntax:

curl -O [URL...]

Example:

curl -O ftp://speedtest.tele2.net/1MB.zip

Output:

curl Command in Linux with Examples - GeeksforGeeks (5)

Uploading Files

If you want to upload a file to a server, for example using FTP (File Transfer Protocol), curl can do that in just one line:

curl -T uploadfile.txt ftp://example.com/upload/
  • -T uploadfile.txt: This tells curl which file to upload (in this case, a file called uploadfile.txt).
  • ftp://example.com/upload/: This is the destination FTP URL where the file will be uploaded.

Handling Authentication

Sometimes the API or site you're trying to access is protected with a username and password. In those cases, you can put your credentials in the command itself using the -u flag.

curl -u username:password https://example.com/api
  • -u username:password: This sends your login details securely with the request.
  • https://example.com/api: The protected API or resource you want to access.

Examples of Curl Command

-C - Option:

This option resumes download which has been stopped due to some reason. This is useful when downloading large files and was interrupted.
Syntax:

curl -C - [URL...]

Example:

curl -C - -O ftp://speedtest.tele2.net/1MB.zip

Output:

curl Command in Linux with Examples - GeeksforGeeks (6)

--limit-rate Option:

This option limits the upper bound of the rate of data transfer and keeps it around the given value in bytes.
Syntax:

curl --limit-rate [value] [URL]

Example:

curl --limit-rate 1000K -O ftp://speedtest.tele2.net/1MB.zip

Output:

curl Command in Linux with Examples - GeeksforGeeks (7)

The command limits the download to 1000K bytes.

-u Option:

curl also provides options to download files from user authenticated FTP servers.

Syntax:

curl -u {username}:{password} [FTP_URL]

Example:

curl -u demo:password -O ftp://test.rebex.net/readme.txt

Output:

curl Command in Linux with Examples - GeeksforGeeks (8)

-T Option:

This option helps to upload a file to the FTP server.

Syntax:

curl -u {username}:{password} -T {filename} {FTP_Location}

If you want to append an already existing FTP file you can use the -a or --append option.

--libcurl Option:

This option is appended to any curl command, it outputs the C source code that uses libcurl for the specified option.

Syntax:

curl [URL...] --libcurl [filename]

Example:

curl https://www.geeksforgeeks.org > log.html --libcurl code.c

Output:

curl Command in Linux with Examples - GeeksforGeeks (9)

The above example downloads the HTML and saves it into log.html and the code in code.c file. The next command shows the first 30 lines of the code.

Sending mail:

If we can transfer data over different protocols, including SMTP, we can use curl to send mails.

Syntax:

curl --url [SMTP URL] --mail-from [sender_mail] --mail-rcpt [receiver_mail] -n --ssl-reqd -u {email}:{password} -T [Mail text file]

DICT protocol:

DICT protocol which can be used to easily get the definition or meaning of any word directly from the command line.

Syntax:

curl [protocol:[dictionary_URL]:[word]

Example:

curl dict://dict.org/d:overclock

Output:

curl Command in Linux with Examples - GeeksforGeeks (10)

Note: There are a number of other options provided by cURL which can be checked on the main page. The libcurl library has been ported into various programming languages. It's advisable to visit the individual project site for documentation.

Conclusion

Lastly, understanding the command line in Linux is essential to maximize efficiency and effectiveness in using the system, with `curl` being an outstanding tool due to its flexibility and robust data transfer capabilities across various protocols. Developed by Daniel Stenberg, `curl` provides simple fetching, uploading, and data manipulation through the Internet. This book has given an in-depth elaboration of what curl can do, how it works, and its various applications, highlighting the need for Linux users seeking full command line utility.


Next Article

How to Compare Files Line by Line in Linux | diff Command

singhyog

Improve

Article Tags :

  • Technical Scripter
  • Linux-Unix
  • Technical Scripter 2018

Similar Reads

  • Linux Commands Linux commands are essential for controlling and managing the system through the terminal. This terminal is similar to the command prompt in Windows. It’s important to note that Linux/Unix commands are case-sensitive. These commands are used for tasks like file handling, process management, user adm 15+ min read
  • File and Directory Manipulation

    File Operations and Compression

    Network and Connectivity

    • How to Monitor System Activity in Linux | top Command top command is used to show the Linux processes. It provides a dynamic real-time view of the running system. Usually, this command shows the summary information of the system and the list of processes or threads which are currently managed by the Linux Kernel. As soon as you will run this command it 10 min read
    • How to Kill a Process in Linux | Kill Command kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process that terminates the process. If the user doesn't specify any signal that is to be sent along with the kill command, then a default TERM signal i 6 min read
    • ifconfig Command Knowing your IP address is fundamental for network administration, troubleshooting, and various Linux system tasks. In this article, we will explore several methods to find your IP address in a Linux environment. Whether you are a seasoned Linux user or just getting started, understanding these meth 10 min read
    • How to Check Network Connectivity in Linux | ping Command Ensuring a stable and reliable internet connection is crucial for seamless navigation and efficient communication in the world of Linux. The "ping" command is a powerful tool that allows users to check the status of their internet connection and diagnose network-related issues. In this article, we w 7 min read
    • How to use SSH to connect to a remote server in Linux | ssh Command Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th 8 min read
    • How to Securely Copy Files in Linux | scp Command Secure file transfer is a crucial part of Linux systems administration. Whether moving sensitive files between local machines or transferring data between servers, SCP (Secure Copy Protocol) provides a fast, secure, and efficient way to copy files over a network. By utilizing SSH (Secure Shell), SCP 11 min read
    • Wget Command in Linux/Unix Wget is the non-interactive network downloader which is used to download files from the server even when the user has not logged on to the system and it can work in the background without hindering the current process. GNU wget is a free utility for non-interactive download of files from the Web. It 6 min read
    • curl Command in Linux with Examples curl is a command-line utility for transferring data to or from a server, employing a range of internet protocols such as HTTP, HTTPS, FTP, SCP, and SFTP.Whether you want to download a file, test a REST API, or simply verify that a website is up and running, curl is your best friend. It is accessed 5 min read
    • How to Compare Files Line by Line in Linux | diff Command In the world of Linux, managing and comparing files is a common task for system administrators and developers alike. The ability to compare files line by line is crucial for identifying differences, debugging code, and ensuring the integrity of data. One powerful tool that facilitates this process i 9 min read
    • Head Command in Linux With Examples Need to quickly view the beginning of a file in Linux? The head command is your best option. This essential command-line tool enables users, developers, and system administrators to preview the start of log files, configuration files, CSV datasets, and other text documents in seconds.The head comman 6 min read

    Text Processing and Manipulation

    Help and Information

    System Administration and Control

    User and Group Management

    Privilege and Security Management

    Process Management and Control

curl Command in Linux with Examples - GeeksforGeeks (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 6393

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.