Download a single file and print the output to standard output (STDOUT) by default
Curl http://www.centos.org
Save the downloaded file to the specified file with the-o/-o option:
-O: Save the file as the file name specified on the command line
-O: Save the file to local using the default file name in the URL
# Download the file locally and name it mygettext.html2 Curl-o mygettext.html http://www.gnu.org/software/gettext/manual/ Gettext.html# Saves the file locally and is named gettext.html5 Curl-o http://www.gnu.org/software/gettext/manual/ gettext.html
You can also use the turn character ">" to turn output to output
Get multiple files at the same time
1 Curl-o url1-o URL2
If you download multiple files from the same site at the same time, Curl tries to reuse the links (connection).
Redirection with the-l option
By default, curl does not send HTTP location headers (redirection). When a requested page is moved to another site, an HTTP loaction header is sent as a request, and the request is redirected to the new address.
For example: When you access google.com, the address is automatically redirected to google.com.hk.
1 Curl http://www.google.com2 <HTML>3 <HEAD>4 <meta http-equiv="Content-type"Content="Text/html;charset=utf-8 "> 5 <title> 302 Moved</title> 7 <body>< Span style= "color: #008080;" > 8 302 moved 9 The document has Moved10 <a href= "http://www.google.com.hk/url?sa=p&hl=zh-cn&pref=hkredirect&pval=yes&q=http:// Www.google.com.hk/&ust=1379402837567135amp;usg=AFQjCNF3o7umf3jyJpNDPuF7KTibavE4aA ">here</a>. </body>12
The above output indicates that the requested file was transferred to HTTP://WWW.GOOGLE.COM.HK.
This is possible by forcing redirection by using the-l option
# Let Curl use address redirection, which will query google.com.hk site 2 curl-l http:///www.google.com
Breakpoint Continuation
Using the-C option, you can use the breakpoint continuation feature for large files, such as:
# when the file ends before the download completes the process 2 $ curl-o http://www.gnu.org/software/gettext/manual/gettext.html20.1%5 # By adding the-C option to continue downloading the file, the downloaded file will not be re-downloaded 6 curl-c-O http://www.gnu.org/software/gettext/manual/ gettext.html21.1%
Using network speed limiting for curl
Limit the maximum network usage of curl with the--limit-rate option
1 # download Speed Max No more than 1000b/second3 Curl--limit-rate 1000b-o http://www.gnu.org/software/gettext/manual/ gettext.html
Download files that have been modified in the specified time
When downloading a file, you can determine the last modified date of the file, if the file has been modified within the specified date, download it, otherwise it will not be downloaded.
This feature can be achieved by using the-Z option:
1 # If the yy.html filehas been updated after 2011/12/21, it will be downloaded 21-dec-http://www.example.com/yy.html
Curl Authorization
A user name and password can be authorized with the-u option when accessing a page that requires authorization
1 Curl-u username:password URL# The usual practice is to enter only the user name at the command line and then prompt for a password, which guarantees that the password will not be compromised when viewing history 4 curl-u username URL
Downloading files from an FTP server
Curl also supports FTP downloads, and if you specify a file path in the URL instead of a specific file name to download, curl lists all the file names in that directory rather than downloading all the files in that directory
# list all folders and files under public_html ftp://ftp_server/public_html/# download xss.php file ftp://FTP_ server/public_html/xss.php
Uploading files to an FTP server
The-t option uploads the specified local file to the FTP server
ftp://ftp.testserver.com"{file1,file2}ftp://ftp.testserver.comftp:// ftp.testserver.com/myfile_1.txt
For more information
Get more link information by using-V and-trace
Querying words through a dictionary
# Query The meaning of bash words 2 Curl dict://dict.org/d:bash# list all available dictionaries 5 Curl Dict://dict.org/show:db # Query The meaning of bash words in the Foldoc dictionary 8 Curl dict://dict.org/d:bash:foldoc
Set up a proxy for curl
-X option to add agent functionality to curl
# Specify proxy host and Port 2 curl-x proxysever.test.com:3128 http://google.co.in
Other web site collation
Saving and using Web site cookie information
# Save cookies from the website to the sugarcookies file 2 curl-d sugarcookies http://localhost/sugarcrm/index.php# Use last saved cookie information 5 curl-b sugarcookies http://localhost/sugarcrm/index.php
Passing Request data
Default curl uses Get method to request data, in this way directly through the URL to pass the data
You can use the--data/-d method to specify that data is passed by post
1# get2 curl-u username https: //api.github.com/user?access_token=xxxxxxxxxx3 4 # post5 curl-u Username--data "param1=value1¶m2=value "Https://api.github.com 6 7 # can also specify a file, Pass the contents of the file as data to the server-side 8 Curl--data @filename https://< Span style= "color: #008000;" >github.api.com/authorizations
Note: By default, if there are special characters in the data passed through post, you first need to pass the special character escape to the server side, if the value contains spaces, you need to convert the space to%20 first, such as:
"value%201" http://hostname.com
In the new version of Curl, a new option--data-urlencode is provided, and the parameters provided by this option automatically escape special characters.
"value 1" http://hostname.com
In addition to using the Get and post protocols, you can specify additional protocols through the-X option, such as:
1 curl-i-X DELETE https://API.GITHUB.CIM
Uploading files
"[email protected]" http://hostname/resource
Curl Common Commands