curl is an open source file transfer tool that can be used in Linux systems. If you want to use this tool well, you need to know the curl command parameters in detail. The following small series will introduce you to the operation example of the Linux curl command. Interested in Friends can come to understand.
uploading and downloading files on Linux curl support, is a comprehensive transfer tool, but traditionally, used to refer to url to download tools.
Syntax: # curl [option] [url]
Common parameters:
-A/--user-agent "string" Set user agent to send to server
-b/--cookie "name=string/file" cookie string or file read location
-c/--cookie-jar "file" Write the cookie to the end of the operation In this file
-C/--continue-at "offset" breakpoints continue
-D/--dump-header "file" Write header information to this file
-e/--referer Source URL
-f/--fail Does not display http error when connection fails
-o/--output Write output to this
-O/--remote-name in the file Write the output to this file, keep the file name of the remote file
-r/--range "range" Retrieve from HTTP/1.1 Or FTP server byte range
-s/--silent silent mode. Do not output anything
-T/--upload-file "file" Upload file
-u/--user "user[:password]" Set server user and password
-w/--write-out [format] After the output is complete
-x/--proxy "host[:port]" Use HTTP proxy on the given port
-#/--progress-bar The progress bar shows the current transfer status
Example:
1. Basic usage
# curl http://www. Linuxidc.com
After execution, the html of www.linuxidc.com will be displayed on the screen.
Ps: Since linux is installed many times, there is no desktop installed, which means There is no browser, so this method is also often used to test whether a server can reach a website
2. Save the accessed webpage
2.1: Save using linux redirection function
# curl http://www.linuxidc.com 》 linuxidc.html
2.2: You can use curl's built-in option:-o (lowercase) to save the page
$ curl -o linuxidc.html http://www.linuxidc.com
After the completion of the operation, the following interface will be displayed. If 100% is displayed, the save is successful
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 79684 0 79684 0 0 3437k 0 --:--:-- --:--:-- --: --:-- 7781k
2.3: You can use curl's built-in option: -O (uppercase) to save the file in the web page
Note that the url after this is specific to a file. Otherwise, you can't catch it
# curl -O http://www.linuxidc.com/hello.sh
3. Test page return value
# curl -o /Dev/null -s -w %{http_code} www.linuxidc.com
Ps: In the script, this is a very common test for the normal use of the website
4, specify the proxy server And its port
Many times you need to use a proxy server for the Internet (for example, when using a proxy server to access the Internet or being blocked by someone else using the curl website), Fortunately, curl supports setting the proxy by using the built-in option:-x
# curl -x 192.168.100.100:1080 http://www.linuxidc.com
5, cookie
Some websites use cookies to record session information. For browsers such as chrome, cookie information can be handled easily, but it can be easily handled by adding relevant parameters in curl
5.1: Save the cookie information in http response. Built-in option:-c (lowercase)
# curl -c cookiec.txt http://www.linuxidc.com
After the execution, the cookie information is stored in cookiec.txt. Br>
5.2: Save the header information in http response. Built-in option: -D
# curl -D cookied.txt http://www.linuxidc.com
After the execution, the cookie information is saved in cookied.txt
Note: The cookie generated by -c (lowercase) is not the same as the cookie of -D.
5.3: Using Cookies
Many websites monitor your cookie information to determine if you are accessing their website in accordance with the rules, so we need to use the saved cookie information. Built-in option: -b
# curl -b cookiec.txt http://www.linuxidc.com
6. Imitating the browser
Some websites need to use specific The browser goes to access them, and some also need to use certain versions. Curl built-in option: -A allows us to specify a browser to access the website
# curl -A “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)” http://www.linuxidc. Com
This will be considered by the server to use IE8.0 to access
7. Forge referer (the chain of stolen)
Many servers will check the referer of http access. To control access. For example: you first visit the home page, and then visit the mailbox page in the home page. The referer address of the access mailbox is the address of the page after the successful home page. If the server finds that the referer address of the mailbox page access is not the address of the home page, it is determined that Is a stealing
Curl built-in option:-e allows us to set referer
# curl -e “www.linuxidc.com” http://mail.linuxidc.com
This will cause the server to think that you are clicking on a link from www.linuxidc.com
8. Download the file
8.1: Use curl to download the file.
#使用内置::o(lowercase)
# curl -o dodo1.jpg http:www.linuxidc.com/dodo1.JPG
#Use built-in option :-O(uppercase)
# curl -O http://www.linuxidc.com/dodo1.JPG
This will save the file to the local name on the server
8.2: Loop download
Sometimes the download image can be the same as the previous part name, the last tail name is different
# curl -O http://www .linuxidc.com/dodo[1-5].JPG
This will save dodo1, dodo2, dodo3, dodo4, dodo5 all
8.3: Download Rename
# curl -O http://www.linuxidc.com/{hello,bb}/dodo[1-5].JPG
Since the downloaded file names for hello and bb are both dodo1, Dodo2, dodo3, dodo4, dodo5. So the second download will overwrite the first download, so you will need to rename the file.
# curl -o #1_#2.JPG http://www.linuxidc.com/{hello,bb}/dodo[1-5].JPG
This is in hello/The file dodo1.JPG will be downloaded as hello_dodo1.JPG, and other files and so on, effectively avoiding file overwriting.
Previous12Next page Total 2 pages
Steam Music is a music player. The biggest highlight of this player is that it can play music during
Emacs is recognized as one of the best code editors, and many users use Emacs on Linux. However, bec
In order to protect the security of computer data, you need to periodically back up
Previously, Xiaobian introduced the Ubuntu 12.04 method of installing the Gnome Shell extension, but
Tips for learning Linux system commands
Ubuntu steps to install VLC player
How to configure yum source in CentOS system
How to use the Linux system Docker command
Solve the problem of installing Linux prompt Boot Efi does not have space to set up
What should I do if the syntax of the Linux Vi editing code is not colored?
CentOS 6.0 manual upgrade to CentOS 6.2 method
Linux system iptables error iptables: Protocol wrong how to do?
Ubuntu OpenSC installation method
How to modify the file time of the Linux system
Putty network error: Connection refused garbled
Win8 and WP developer account fit
Win10 official version of the U disk how to buy?
Remove the Win10 preview desktop watermark in the lower right corner of the desktop
System Home - Windows 7 Deployment Required Tools Collection System
Set the win8.1 update power button to achieve multiple shutdown options
Teach you to clear the system self-starting program (1)
Why can Word only be opened in safe mode? Word does not open in safe mode