Introduction and comparison of the curl and wget commands in Linux
- 2020-05-30 21:59:04
- OfStack
This article covers the curl and wget commands in Linux, both of which are tools for downloading files. Here's a look at the details:
1. wget
wget is the most commonly used download command for linux. The 1-like usage is: wget + space + url path to download the file
Case 1:
wget http://www.minjieren.com/wordpress-3.1-zh_CN.zip
Download the file and save it to the current directory. The default file name is url last/last, wordpress-3.1-zh_CN.zip
Example 2:
wget -O myfile http://www.minjieren.com/wordpress-3.1-zh_CN.zip
You can specify the file name with the -O parameter, which in this case is myfile
Example 3:
wget www.baidu.com
An index.html file is generated in the current directory
2. curl
In Linux, curl is a file transfer tool that USES URL rules to work under the command line. It is a very powerful http command line tool. It supports the upload and download of files, and is a comprehensive transfer tool, but traditionally, it is used to call url as the download tool.
Syntax: # curl [option] [url]
Common parameters:
Ex. :
curl -O http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-i586.tar.gz
Download files saved to the current directory, file name is the last one url by default/later, here is the jdk - 8 u91 - linux - i586. tar. gz.
Note: the -O parameter must be added, otherwise the file contents will be displayed directly on the console.
Note: these two command tools, linux system default not 1 must have, if not, you need to install their own. If it's under ubuntu.
The following command can be used for installation
sudo apt-get install curl
The differences are as follows:
1.curl is supported by the library libcurl, and wget is a pure command-line command.
2.curl supports more protocols. curl supports FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS, POP3, IMAP, SMTP and HTTPS the time this writing Wget supports HTTP HTTPS and FTP
3.curl supports HTTP1.1 (also 1.0) by default, while wget only supports HTTP1.0. To quote a passage from wget, man page,
Please be aware that Wget needs to know the size of the POST data in advance. It's not quite clear how to work around this limitation inherent in HTTP/1.0. Although HTTP/1.1 introduces chunked transfer that doesn't require knowing the request length in advance, a client can't use chunked unless it knows it's talking to an HTTP/1.1 server. And it can't know that until it receives a response, which in turn requires the request to have been completed -- a chicken-and-egg problem.
4.curl can support a sequence or collection of URL when specifying a link to download, whereas wget cannot;
5.wget supports recursive downloads, while curl does not. (this is one of the main benefits of wget. wget also has advantages.)
conclusion