If you have ever used cURL to retrieve the output of a file, believe me, saving that output to a file only takes a few more characters. Example #1: Saving a file with the remote file name You can use the or option to save the output to a local file in the current working directory using the remote file name. -O --remote-name $ curl -O https://example.com/files/README In this example, the file will be created or overwritten. ./README Example #2: Saving a file with another file name You can use the or option followed by a file name you want to save the output. -o --output $ curl -o my-readme-file https://example.com/files/README $ curl -o ~/save/to/other/path https://example.com/files/README Similar to the above example, the output file will be created or overwritten. Example #3: Saving a file using the output redirection operator In Linux, you can use the output redirection operator to write the output to a specific file. > $ curl https://example.com/files/README > ~/save/to/specific/path If you want to append the output to that file, you can use the output append operator instead. >> Example #4: Downloading multiple files with a single command If you want to download multiple files, you can add more or options: -o -O $ curl \ -O https://example.com/files/file-1 \ -o file-2 https://example.com/files/file-2 \ -o file-3 https://example.com/files/file-3 Example #5: Dealing with the HTTP redirection If the target server responded with the HTTP redirection code (3xx) for the requested file, the local file you downloaded would be empty. In this case, you have to add the or option to tell cURL to follow the redirects. -L --location $ curl -L -O https://example.com/files/README You can use the option to specify the maximum number of redirects will be followed to avoid infinite redirection-followings: --max-redirs <number> $ curl -L --max-redirs 10 -O https://example.com/files/README In this example, after 10 attempts, cURL will throw an error and abort the download process. Example #6: Speed limiting If you want to limit the downloading speed, you can use the option to set the maximum number of bytes downloaded per second. The number of bytes can be abbreviated by appending a suffix: kilobytes (k or K), megabytes (m or M), and gigabytes (g or G). --limit-rate <speed> To limit 512 bytes/second and 2 megabytes/second: $ curl -- -rate 512 -O https://example.com/files/README $ curl -- -rate 2M -O https://example.com/files/README limit limit Example #7: Downloading a part of a file cURL allows you to download a part of a file by using the or option. -r <range> --range <range> For example, to get the first 500 bytes of a file: $ curl -r 0-500 -O https://example.com/files/README To get the last 300 bytes of a file: $ curl -r -300 -O https://example.com/files/README Example #8: Resuming downloading a file What would you do if the download process was interrupted, for example, you pressed ? Re-download? Ctrl + C Do not! Because cURL supports resuming a file downloading process at the given offset by the option. If you do not know the exact value of the offset, do not worry, you just need to specify to tell cURL to automatically find out that value. -C <offset> -C - $ curl -C - -O https://example.com/files/README Example #9: Using basic authentication If the requested file requires basic authentication, you need to use the option followed by the credential which is in the form of : -u user:password $ curl -u user:password -O https://example.com/files/README To read more about basic authentication, you can read the article . 3 methods to use basic authentication with cURL Example #10: Using a proxy If you want to use a proxy to download a file, you need to use option followed by the proxy address, say : -x http://111.111.111.111:8080 $ curl -x http://111.111.111.111:8080 -O https://example.com/files/README To see more examples, you can read the article . How to use a proxy with cURL Example #11: Entering the silent mode If you do not want cURL to show the progress meter or error messages, you can use the or option: -s --silent $ curl -s -O https://example.com/files/README Previously published at https://trubavuong.com/articles/curl-download-file/