How to Download any File using cURL on Linux

Endrit Qerreti

Endrit Qerreti

cURL is a very popular and useful command line tool that you can use to download files from the internet but not only, cURL is similar to wget but cURL has a lot of more features and it is the perfect tool to use when downloading or transferring data on any system.

In this tutorial you will learn how to install cURL and how to download files.

cURL Supports

DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, HTTP/3, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, SCRAM-SHA, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling and more.

How to install cURL?

Before we start with the tutorial you must have curl installed on your system, if you don't, then you simply can install it via the command below

Ubuntu

sudo apt install curl

CentOS/Red Hat/ Fedora

yum install curl

Arch Linux

sudo pacman -Sy curl

Downloading Files

Fetch a remote file

By default cURL command without an argument will only fetch the file, so the command below will only fetch the txt file and it will display the content on the terminal.

curl https://site.com/file.txt

Download and Save the File

To download and save the file to the directory from where you are running curl, the flag -o needs be used

curl -o myfile.txt https://urltofile.com/file.txt

The command above will download the file.txt named as myfile.txt to the same directory, let's say you ran curl from home directory, then the downloaded file will be on home directory.

For example : I downloaded the file robots.txt named as myfile on my Downloads folder

If you want to download a file to a specific directory, you can do so by running curl from the folder where you want it downloaded

for example navigate to the folder by using cd command

cd Downloads - will take you to Downloads folder, then once you are in downloads folder simply open terminal and run curl from there.

or using the flags

--create-dirs -0 --output-dir /path/where/to/download/thefile

curl --create-dirs -O --output-dir /path/where/to/download/thefile https://example.com/file.zip

Download Multiple files

To download multiple files at once make sure to use -o flag for each url, so if you wanted to download two files, the command should look like this one below

curl -o url1 -o url2

Resume an Interrupted Download

Assuming your internet connection got cut while you were downloading an ISO file, to resume that download you need to use this command

curl -L -O -C - http://url/file.iso

See cURL Version

curl --version

See cURL Manual

To get the full list of commands in cURL type:

curl --manual

Conclusion

In this tutorial you learned how to install cURL on Linux and how to download files by using it.