download a single file and print the output to the standard output (STDOUT) in Curl HTTP by default://www.centos.orgSave the downloaded file to the specified file via the-o/-o option:-o: Save the file as the file name specified on the command line-O: Save the file to a local by using the default file name in the URL1# Download the file locally and name it mygettext.html2 Curl-o mygettext.html http://www.gnu.org/software/gettext/manual/gettext.html3 4# Save the file locally and name it gettext.html5 Curl-o http://www.gnu.org/software/gettext/manual/gettext.htmlYou can also use the turn character ">"Turn output for output and get multiple files simultaneously1 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). Through-l option to redirect 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. Copy Code1 Curl http://www.google.com2 <HTML> 3 <HEAD> 4 <meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" > 5 <tit le>302 moved</title> 6 </HEAD> 7 <BODY> 8 The document has movedTen <a href= "http://www.google.com.hk/url?sa=p&hl=zh-cn&pref=hkredirect&pval=yes& AMP;Q=HTTP://WWW.GOOGLE.COM.HK/&AMP;UST=1379402837567135AMP;USG=AFQJCNF3O7UMF3JYJPNDPUF7KTIBAVE4AA "> here</a>.11 </body>12 </HTML>Copy Code The above output indicates that the requested file was transferred to http://www.google.com.hk. this is possible by using the-l option for forced redirection1# Let Curl use address redirection, at which point the google.com.hk site is queried2 curl-l http://www.google.comThe breakpoint continues to pass by using the-The C option allows you to use the breakpoint continuation feature for large files, such as: Copy code1# When the file ends the process before the download is complete2 $ Curl-o http://www.gnu.org/software/gettext/manual/gettext.html3 ############## 20.1%4 5 # by adding-The c option continues to download the file and the downloaded file will not be re-downloaded6 curl-c-O http://www.gnu.org/software/gettext/manual/gettext.html7 ############### 21.1%copy code to curl using network speed limit through--limit-The rate option limits the maximum network usage of Curl1 # download Speed Max no more than 1000b/second2 3 Curl--limit-rate 1000b-o http://www.gnu.org/software/gettext/manual/gettext.htmldownload a file that has been modified in the specified time when a file is downloaded, the last modified date of the file can be judged, if the file has been modified within the specified date, it will be downloaded or not. This feature is available by using the-z option to achieve:1 # If yy.html file is 2011/12/the update will not be downloaded until after 21.2 curl-z 21-dec-11 http://www.example.com/yy.htmlCurl is authorized to access pages that require authorization by-the U option provides a user name and password for authorization1 Curl-u username:password URL2 3# It is common practice 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 history4 Curl-u username URL download file from FTP server curl also supports FTP download, if you specify a file path in the URL rather than a specific file name to download, curl lists all the file names in that directory instead of downloading all files in that directory1# List all folders and files under public_html2 curl-u ftpuser:ftppass-o ftp://ftp_server/public_html/3 4# download xss.php file5 Curl-u ftpuser:ftppass-o ftp://ftp_server/public_html/xss.phpupload files to FTP server via-T option to upload the specified local file to the FTP server copy code # Upload the MyFile.txt file to the server Curl-U ftpuser:ftppass-t myfile.txt ftp://ftp.testserver.com# Upload multiple files at the same time Curl-U ftpuser:ftppass-t "{file1,file2}" ftp://ftp.testserver.com# Save content from standard input to server-specified file Curl-U ftpuser:ftppass-t-ftp://Ftp.testserver.com/myfile_1.txtCopy the code for more information by using the-V and-Trace gets more link information copy code by querying the word dictionary1# Query The meaning of bash words2 Curl Dict://Dict.org/d:bash3 4# List all available dictionaries5 Curl Dict://dict.org/show:db6 7# Query The meaning of bash words in the Foldoc dictionary8 Curl Dict://Dict.org/d:bash:foldocCopy code set agent for Curl-x option to add agent functionality to Curl1# Specify proxy host and port2 curl-x proxysever.test.com:3128 http://google.co.inOther websites organize and save and use cookies information1# Save cookies from the website to the sugarcookies file2 curl-d sugarcookies http://localhost/sugarcrm/index.php3 4# Use Last saved cookie information5 Curl-b sugarcookies http://localhost/sugarcrm/index.phpPass-through request data default curl uses get to request data, which can be passed directly through the URL--data/-d mode specifies that data is passed using postCopy Code1# 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.com6 7# You can also specify a file to pass the contents of the file as data to the server side8 Curl--data @filename https://github.api.com/authorizationsCopy Code Note: By default, when passing past data via post, special characters must first be passed to the server side, and if the value contains spaces, the space must first be converted to%20, such as:1 curl-d "value%201" http://hostname.comIn the new version of Curl, new options are available--data-UrlEncode, the parameters provided by this option automatically escape special characters. 1 Curl--data-urlencode "value 1" http://hostname.comIn addition to using the Get and post protocols, you can also pass-The X option specifies additional protocols, such as:1 curl-i-X DELETE https://Api.github.cimUploading Files1 Curl--form "[email protected]" http://Hostname/resource
Common commands for Linux under Curl