Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux curl command

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail the use of the Linux curl command for you. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Linux common command curl is a file transfer tool that uses URL rules to work under the command line. It can be said to be a very powerful http command line tool. It supports the upload and download of files, is a comprehensive transmission tool, but according to tradition, it is customary to call url a download tool, the following is to share with you the specific use of Linux commands curl commands.

Syntax # curl [option] [url] parameter-A/--user-agent sets the user agent to send to the server-b/--cookie cookie string or file read location-write cookie to this file after the c/--cookie-jar operation ends-C/--continue-at breakpoint continues-D/--dump-header Write header information to this file-e/--referer source URL-http error is not displayed when f/--fail connection fails-o/--output writes output to this file-O /-- remote-name writes the output to the file Keep the file name of the remote file-r/--range retrieves the byte range from the HTTP/1.1 or FTP server-s/--silent mute mode. Do not output anything-T/--upload-file upload file-u/--user set server user and password-w/--write-out [format] what output is complete-x/--proxy uses HTTP proxy-# /-- progress-bar on a given port The progress bar shows the current transfer status instance file download

The curl command can be used to perform downloads, send various HTTP requests, specify HTTP headers, and so on. If the system does not have curl, you can install it using yum install curl, or you can download and install it. Curl outputs the download file to stdout, the progress information to stderr, and does not display progress information using the-- silent option.

The command curl URL-- silent outputs the download file to the terminal, and all downloaded data is written to stdout.

Use the option-O to write the downloaded data to a file, and you must use the absolute address of the file:

Curl http://man.linuxde.net/text.iso-- silent-O option-o writes the download data to a file with the specified name and uses-- progress to display the progress bar:

Curl http://man.linuxde.net/test.iso-o filename.iso-- progress # # 100.0% breakpoint continuation

Curl can continue to download from a specific file offset, and it can download some files by specifying a cheap amount:

Curl URL/File-C offset # offset is an integer in bytes. If you let curl automatically infer the correct continuation position, use-C -: curl-C-URL to set the reference page string using curl

The reference page is a string located in the HTTP header to indicate from which page the user arrived at the current page. If the user clicks on a connection in page A, the user will jump to page B, and the reference page string in the header of page B contains the URL of page A.

Use the-- referer option to specify the reference page string:

Curl-- referer http://www.google.com http://man.linuxde.net sets cookies with curl

Use the-- cookie "COKKIES" option to specify cookie, and multiple cookie are separated by semicolons:

Curl http://man.linuxde.net-- cookie "user=root;pass=123456" saves cookie as a file, using the-- cookie-jar option:

Curl URL-- cookie-jar cookie_file sets the user agent string with curl

Some Web sites are prompted to be accessed only using IE browsers, because these sites have a check user agent, which can be set to IE using curl, so that they can be accessed. Use the-- user-agent or-An option:

Curl URL-user-agent "Mozilla/5.0" curl URL-A "Mozilla/5.0" other HTTP header information can also be sent using curl, using-H "header message" to pass multiple header information, for example:

Bandwidth control and download quota for curl-H "Host:man.linuxde.net"-H "accept-language:zh-cn" URLcurl

Use-- limit-rate to limit the download speed of curl:

Curl URL-the download speed limit is specified with k (kilobytes) and m (megabytes) in the limit-rate 50k command.

Use-- max-filesize to specify the maximum file size that can be downloaded:

Curl URL-- max-filesize bytes if the file size exceeds the limit, the command returns a non-zero exit code, or 0 if the command is normal.

Authentication with curl

Use the curl option-u to complete the authentication of HTTP or FTP. You can specify a password, or enter a password in subsequent operations without specifying a password:

Curl-u user:pwd http://man.linuxde.net curl-u user http://man.linuxde.net prints only response header information

With-I or-head, you can print only the HTTP header information:

[root@localhost text] # curl-I http://man.linuxde.net HTTP/1.1 200 OK Server: nginx/1.2.5 date: Mon, 10 Dec 2012 09:24:34 GMT Content-Type: text/html Charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding X-Pingback: http://man.linuxde.net/xmlrpc.php what is the Linux system Linux is a UNIX-like operating system that is free to use and spread freely. It is a multi-user, multi-tasking, multi-threaded and multi-CPU operating system based on POSIX. Using Linux, you can run major Unix tools, applications and network protocols.

On the use of the Linux curl command to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report