Skip to content

curl MacOS command

The MacOS curl command is a powerful tool for transferring data using various protocols. It can be used for making HTTP requests, downloading files, sending data to servers, and more. With its flexible options and easy-to-use syntax, curl is a must-have tool for developers and system administrators working in a MacOS environment.

curl Syntax:

Terminal window
curl [options] [URL]

Options:

OptionDescription
-X, —requestSpecify the request method
-H, —headerInclude HTTP headers in the request
-d, —dataSend data in the request body
-o, —outputWrite output to a file instead of stdout
-O, —remote-nameWrite output to a file using remote name
-i, —includeInclude the HTTP response headers in the output
-L, —locationFollow redirects
-v, —verboseMake the operation more talkative
-I, —headFetch the headers only, no body

Parameters:

ParameterDescription
URLThe URL to make the request to

curl bash Examples:

Download a File

Terminal window
curl -O https://example.com/file.zip

Downloads a file from the specified URL and saves it with the original file name.

Save Response to File

Terminal window
curl -s https://example.com/api/data -o output.json

Retrieves data from an API endpoint and saves the response to a file named “output.json”.

Follow Redirects

Terminal window
curl -L https://example.com

Follows any redirects when accessing the specified URL.

Send POST Request with Data

Terminal window
curl -X POST https://example.com/api/post -d "key1=value1&key2=value2"

Sends a POST request with the specified data to the API endpoint.

Display Response Headers

Terminal window
curl -I https://example.com

Displays only the response headers of the specified URL.

Limit Transfer Speed

Terminal window
curl --limit-rate 1M https://example.com/largefile.zip

Limits the download transfer rate to 1 megabyte per second when retrieving a large file.

How do I use curl in MacOS?

To use the curl command in MacOS, execute the following command:

Terminal window
curl --option <value>

How can I download a file using curl in MacOS?

To download a file using curl in MacOS, use the following command:

Terminal window
curl -O http://example.com/file.txt

How do I save the output of a curl command to a file in MacOS?

To save the output of a curl command to a file in MacOS, run the following command:

Terminal window
curl http://example.com/data.txt -o output.txt

How can I follow redirects with curl in MacOS?

To follow redirects with curl in MacOS, add the -L option to the command. Here’s an example:

Terminal window
curl -L http://example.com/redirectingURL

How do I set a specific user agent with curl in MacOS?

To set a specific user agent with curl in MacOS, use the -A option followed by the user agent string. For example:

Terminal window
curl -A "Mozilla/5.0" http://example.com

How can I send POST data with curl in MacOS?

To send POST data with curl in MacOS, use the -d option followed by the data to be sent. Here’s an example:

Terminal window
curl -d "param1=value1&param2=value2" -X POST http://example.com/api

How do I perform a HEAD request with curl in MacOS?

To perform a HEAD request with curl in MacOS, use the -I option. Here’s an example:

Terminal window
curl -I http://example.com

How can I download multiple files with curl in MacOS?

To download multiple files with curl in MacOS, list the URLs separated by spaces in a single command. For example:

Terminal window
curl -O http://example.com/file1.txt http://example.com/file2.txt

Applications of the curl command

  • Download files from the internet
  • Upload files to a server
  • Send and receive data over various protocols (HTTP, FTP, etc.)
  • Automate web-related tasks
  • Troubleshoot network-related issues