When we use linux, we often encounter the situation of downloading files, so how do we use commands to download files in linux?
Today, I want to share with you two commonly used file download commands:
- wget
- curl
Syntax
curl [options] [URL...]
wget [option] [URL]
Curl:
- -L, –location
(HTTP) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. - -d, –data <data>
(HTTP) Sends the specified data in a POST request to the HTTP server - -o, –output <file>
Write output to <file> instead of stdout. - -O, –remote-name
Write output to a file named as the remote file - -H, –header <header/@file>
Pass custom header(s) to server - -e, –referer <URL>
Referrer URL
wget:
- -o logfile
–output-file=logfile
Log all messages to logfile. - -a logfile
–append-output=logfile
Append to logfile.
Examples
Use wget to download files
In the following example, we will use the wget command to download the ubuntu iso file. It is recommended to enclose the URL in double quotation marks (“).
wget "https://mirrors.nju.edu.cn/ubuntu-releases/21.04/ubuntu-21.04-desktop-amd64.iso"
If you want the standard output not to output content, you can use the -o or -a option to write the output to the log file.
wget "https://mirrors.nju.edu.cn/ubuntu-releases/21.04/ubuntu-21.04-desktop-amd64.iso" -o logfile
Use curl to download files
In the following example, we will use the curl command to download the Ubuntu iso file.
curl -o ubuntu.iso https://mirrors.nju.edu.cn/ubuntu-releases/21.04/ubuntu-21.04-desktop-amd64.iso
curl -O https://mirrors.nju.edu.cn/ubuntu-releases/21.04/ubuntu-21.04-desktop-amd64.iso