How to download a file with curl on Linux/Unix command line

To download a file using curl on the Linux/Unix command line, you can use the following syntax:

curl -O <URL>

For example, to download a file named “example.txt” from “http://example.com/example.txt“, you would use the command:

curl -O http://example.com/example.txt

This will download the file and save it to the current working directory with the same name as the file on the server (example.txt in this case).

You can also specify a different name for the file when you save it using the -o option, like this:

curl -o myfile.txt http://example.com/example.txt

This will download the file and save it as “myfile.txt” in the current working directory.

If you want to download a file and save it to a specific directory, you can use the -L option to follow redirects and -o option to specify a file name and path.

curl -L -o /path/to/save/myfile.txt http://example.com/example.txt

You can also add the -C - to continue a download, this is useful when your connection breaks or the download is interrupted.

curl -C - -o myfile.txt http://example.com/example.txt

You can also check download progress using -# option, this will show a progress bar:

curl -# -o myfile.txt http://example.com/example.txt

It’s important to mention that some servers may require authentication, in that case, you can use -u option to provide your credentials like this:

curl -u username:password -o myfile.txt http://example.com/example.txt

You can use --remote-name option to save the file with the same name as it has on the server.

curl --remote-name http://example.com/example.txt

Please keep in mind that downloading copyrighted material without permission is illegal in most countries.

Leave a Comment