Linux Curl command detailed and instance sharing _linux

Source: Internet
Author: User
Tags add time curl http authentication http post ranges

Linux curl is a file transfer tool that uses URL rules to work at the command line. It supports the uploading and downloading of files, so it is a comprehensive transmission tool, but traditionally, the URL is used as the download tool.

One, Curl command parameters, there are many I have not used, do not know the right to translate, if the wrong place, please correct me.

Attach to target file when uploading files-a/--append

-a/--user-agent <string> set user agent to send to server

-Anyauth can use the "any" authentication method

-b/--cookie <name=string/file> Cookie string or file read location

-Basic authentication using HTTP

-b/--use-ascii using ASCII/text transfer

Write cookies to this file after the-c/--cookie-jar <file> operation is complete

-c/--continue-at <offset> Breakpoint continued turn

-d/--data <data> HTTP Post Way data transfer

--data-ascii <data> Post data in ASCII mode

--data-binary <data> post data in binary mode

--negotiate using HTTP Authentication

--digest using digital authentication

--DISABLE-EPRT prohibit the use of eprt or LPRT

--DISABLE-EPSV prohibit the use of EPSV

-d/--dump-header <file> Write header information to this file

--egd-file <file> Set EGD socket path for random data (SSL)

--tcp-nodelay using the Tcp_nodelay option

-e/--referer Source URL

-e/--cert <cert[:p asswd]> client certificate file and password (SSL)

--cert-type <type> certificate file type (Der/pem/eng) (SSL)

--key <key> private Key file name (SSL)

--key-type <type> private key file type (Der/pem/eng) (SSL)

--pass <pass> private Key password (SSL)

--engine <eng> Encryption engine uses (SSL). "--engine List" for list

--cacert <file> CA Certificate (SSL)

--capath <directory> CA directory (made using C_rehash) to verify peer against (SSL)

--ciphers <list> SSL Password

--compressed requires that the return is a compressed situation (using deflate or gzip)

--connect-timeout <seconds> Set Maximum request time

--create-dirs establish a directory hierarchy of local directories

--crlf upload is to turn LF into CRLF.

Do not display HTTP error when-f/--fail connection fails

--ftp-create-dirs If the remote directory does not exist, create a remote directory

--ftp-method [MULTICWD/NOCWD/SINGLECWD] controls the use of CWD

--FTP-PASV use PASV/EPSV instead of ports

--ftp-skip-pasv-ip when using PASV, ignore the IP address

--ftp-ssl attempts to use SSL/TLS for FTP data transfer

--FTP-SSL-REQD requires SSL/TLS to be used for FTP data transfer

-f/--form <name=content> analog HTTP form submission data

-form-string <name=string> analog HTTP form submission data

-g/--globoff disable URL sequences and scopes using {} and []

-g/--get send data in Get way

-h/--help Help

-h/--header <line> Custom header information passed to the server

--ignore-content-length the length of the HTTP header information ignored

-i/--include output includes protocol header information

-i/--head Display only Document information

Read-j/--junk-session-cookies from file ignore session cookie

-Interface <interface> Specify network interface/address usage

-Krb4 < level > enabled with the specified security level KRB4

-j/--junk-session-cookies read file into ignore session cookie

--interface <interface> Use the specified network interface/address

--KRB4 <level> use KRB4 with specified security level

-k/--insecure allows you to not use certificates to SSL sites

-k/--config specified configuration file read

-l/--list-only lists the file names under the FTP directory

--limit-rate <rate> Set Transmission speed

--local-port<num> Force Local port number

-m/--max-time <seconds> Set Maximum transfer time

--max-redirs <num> Set the maximum number of directories to read

--max-filesize <bytes> Set maximum downloaded file total

-m/--manual Display Full Manual

-N/--NETRC read the username and password from the Netrc file

--netrc-optional use the. netrc or URL to overwrite-n

--NTLM using HTTP NTLM authentication

-n/--no-buffer Disable buffered output

-o/--output writes the output to the file.

-o/--remote-name writes the output to the file, keeping the file name of the remote file

-p/--proxytunnel using HTTP Proxy

--proxy-anyauth Select any proxy authentication method

--proxy-basic use Basic authentication on the agent

--proxy-digest using digital authentication on the agent

--PROXY-NTLM use NTLM authentication on the agent

-p/--ftp-port <address> use port addresses instead of using PASV

Send commands to the server before-q/--quote <cmd> file transfer

-r/--range <range> retrieving byte ranges from http/1.1 or FTP servers

--range-file Read (SSL) random files

-r/--remote-time to keep remote file time when generating files locally

Number of retries when the--retry <num> transport problem occurs

Set the retry interval when the--retry-delay <seconds> transport problem occurs

Set maximum retry time when a problem occurs with--retry-max-time <seconds> transmission

-s/--silent Mute mode. Don't output anything.

-s/--show-error Display Error

--SOCKS4

--SOCKS5

--stderr <file>
-t/--telnet-option <OPT=val> telnet option settings

--trace <file> Debug the specified file

--trace-ascii <file> like-tracking but no hex output

When--trace-time trace/verbose output, add time stamp

-t/--upload-file <file> Uploading files

--url <URL> spet URL to work with

-u/--user <user[:p assword]> Set the server's user and password

-u/--proxy-user <user[:p assword]> set Proxy user name and password

-v/--verbose

-v/--version Display version Information

-w/--write-out [format] What output is finished

-x/--proxy

-x/--request <command> Specify what command

-y/--speed-time the time it takes to give up the speed limit. Default is 30

-y/--speed-limit Stop transmission speed limit, speed time ' sec

-z/--time-cond Transfer Time settings

-0/--http1.0 uses HTTP 1.0

-1/--tlsv1 using TLSV1 (SSL)

-2/--sslv2 using SSLv2 (SSL)

SSLv3 (SSL) used by -3/--sslv3

--3p-quote Like-q for the source URL to 3rd party transfer

--3p-url using URLs for third party delivery

--3p-user uses username and password for third party delivery

-4/--ipv4 Use IP4

-6/--ipv6 Use IP6

-#/--progress-bar displays current delivery status with a progress bar

Attach to target file when uploading files-a/--append

-a/--user-agent <string> set user agent to send to server

-Anyauth can use the "any" authentication method

-b/--cookie <name=string/file> Cookie string or file read location

-Basic authentication using HTTP

-b/--use-ascii using ASCII/text transfer

Write cookies to this file after the-c/--cookie-jar <file> operation is complete

-c/--continue-at <offset> Breakpoint continued turn

-d/--data <data> HTTP Post Way data transfer

--data-ascii <data> Post data in ASCII mode

--data-binary <data> post data in binary mode

--negotiate using HTTP Authentication

--digest using digital authentication

--DISABLE-EPRT prohibit the use of eprt or LPRT

--DISABLE-EPSV prohibit the use of EPSV

-d/--dump-header <file> Write header information to this file

--egd-file <file> Set EGD socket path for random data (SSL)

--tcp-nodelay using the Tcp_nodelay option

-e/--referer Source URL

-e/--cert <cert[:p asswd]> client certificate file and password (SSL)

--cert-type <type> certificate file type (Der/pem/eng) (SSL)

--key <key> private Key file name (SSL)

--key-type <type> private key file type (Der/pem/eng) (SSL)

--pass <pass> private Key password (SSL)

--engine <eng> Encryption engine uses (SSL). "--engine List" for list

--cacert <file> CA Certificate (SSL)

--capath <directory> CA directory (made using C_rehash) to verify peer against (SSL)

--ciphers <list> SSL Password

--compressed requires that the return is a compressed situation (using deflate or gzip)

--connect-timeout <seconds> Set Maximum request time

--create-dirs establish a directory hierarchy of local directories

--crlf upload is to turn LF into CRLF.

Do not display HTTP error when-f/--fail connection fails

--ftp-create-dirs If the remote directory does not exist, create a remote directory

--ftp-method [MULTICWD/NOCWD/SINGLECWD] controls the use of CWD

--FTP-PASV use PASV/EPSV instead of ports

--ftp-skip-pasv-ip when using PASV, ignore the IP address

--ftp-ssl attempts to use SSL/TLS for FTP data transfer

--FTP-SSL-REQD requires SSL/TLS to be used for FTP data transfer

-f/--form <name=content> analog HTTP form submission data

-form-string <name=string> analog HTTP form submission data

-g/--globoff disable URL sequences and scopes using {} and []

-g/--get send data in Get way

-h/--help Help

-h/--header <line> Custom header information passed to the server

--ignore-content-length the length of the HTTP header information ignored

-i/--include output includes protocol header information

-i/--head Display only Document information

Read-j/--junk-session-cookies from file ignore session cookie

-Interface <interface> Specify network interface/address usage

-Krb4 < level > enabled with the specified security level KRB4

-j/--junk-session-cookies read file into ignore session cookie

--interface <interface> Use the specified network interface/address

--KRB4 <level> use KRB4 with specified security level

-k/--insecure allows you to not use certificates to SSL sites

-k/--config specified configuration file read

-l/--list-only lists the file names under the FTP directory

--limit-rate <rate> Set Transmission speed

--local-port<num> Force Local port number

-m/--max-time <seconds> Set Maximum transfer time

--max-redirs <num> Set the maximum number of directories to read

--max-filesize <bytes> Set maximum downloaded file total
-m/--manual Display Full Manual

-N/--NETRC read the username and password from the Netrc file

--netrc-optional use the. netrc or URL to overwrite-n

--NTLM using HTTP NTLM authentication

-n/--no-buffer Disable buffered output

-o/--output writes the output to the file.

-o/--remote-name writes the output to the file, keeping the file name of the remote file

-p/--proxytunnel using HTTP Proxy

--proxy-anyauth Select any proxy authentication method

--proxy-basic use Basic authentication on the agent

--proxy-digest using digital authentication on the agent

--PROXY-NTLM use NTLM authentication on the agent

-p/--ftp-port <address> use port addresses instead of using PASV

Send commands to the server before-q/--quote <cmd> file transfer

-r/--range <range> retrieving byte ranges from http/1.1 or FTP servers

--range-file Read (SSL) random files

-r/--remote-time to keep remote file time when generating files locally

Number of retries when the--retry <num> transport problem occurs

Set the retry interval when the--retry-delay <seconds> transport problem occurs

Set maximum retry time when a problem occurs with--retry-max-time <seconds> transmission

-s/--silent Mute mode. Don't output anything.

-s/--show-error Display Error

--SOCKS4

--SOCKS5

--stderr <file>

-t/--telnet-option <OPT=val> telnet option settings

--trace <file> Debug the specified file

--trace-ascii <file> like-tracking but no hex output

When--trace-time trace/verbose output, add time stamp

-t/--upload-file <file> Uploading files

--url <URL> spet URL to work with

-u/--user <user[:p assword]> Set the server's user and password

-u/--proxy-user <user[:p assword]> set Proxy user name and password

-v/--verbose

-v/--version Display version Information

-w/--write-out [format] What output is finished

-x/--proxy

-x/--request <command> Specify what command

-y/--speed-time the time it takes to give up the speed limit. Default is 30

-y/--speed-limit Stop transmission speed limit, speed time ' sec

-z/--time-cond Transfer Time settings

-0/--http1.0 uses HTTP 1.0

-1/--tlsv1 using TLSV1 (SSL)

-2/--sslv2 using SSLv2 (SSL)

SSLv3 (SSL) used by -3/--sslv3

--3p-quote Like-q for the source URL to 3rd party transfer

--3p-url using URLs for third party delivery

--3p-user uses username and password for third party delivery

-4/--ipv4 Use IP4

-6/--ipv6 Use IP6

-#/--progress-bar displays current delivery status with a progress bar

Second, common curl examples

1, crawl the page content into a file

[Root@krlcgcms01 mytest]# Curl-o home.html http://www.jb51.net

[Root@krlcgcms01 mytest]# Curl-o home.html http://www.jb51.net

2, with-O (uppercase), the following URL to specific to a file, or can't catch down. We can also use the regular to crawl things

[Root@krlcgcms01 mytest]# Curl-o

[Root@krlcgcms01 mytest]# Curl-o

3, analog form information, analog login, save cookie Information

[Root@krlcgcms01 mytest]# curl-c/cookie_c.txt-f log=aaaa-f pwd=****** http://www.jb51.net/wp-login.php

[Root@krlcgcms01 mytest]# curl-c/cookie_c.txt-f log=aaaa-f pwd=****** http://www.jb51.net/wp-login.php

4, analog form information, analog login, save header information

[Root@krlcgcms01 mytest]# curl-d/cookie_d.txt-f log=aaaa-f pwd=****** http://www.jb51.net/wp-login.php

[Root@krlcgcms01 mytest]# curl-d/cookie_d.txt-f log=aaaa-f pwd=****** http://www.jb51.net/wp-login.php

The cookie produced by-c (lowercase) is not the same as the cookie in-D.

5, use cookie file

[Root@krlcgcms01 mytest]# curl-b./cookie_c.txt http://www.jb51.net/wp-admin

[Root@krlcgcms01 mytest]# curl-b./cookie_c.txt http://www.jb51.net/wp-admin

6, the breakpoint continues to pass,-C (uppercase)

[Root@krlcgcms01 mytest]# curl-c-O

7, the transfer of data, preferably with the login page test, because you pass the value of the past, curl back to grasp the data, you can see you pass the value has not succeeded

[Root@krlcgcms01 mytest]# curl-d log=aaaa http://www.jb51.net/wp-login.php

[Root@krlcgcms01 mytest]# curl-d log=aaaa http://www.jb51.net/wp-login.php

8, display the crawl error, the following example, it is clear that.

[Root@krlcgcms01 mytest]# curl-f HTTP://WWW.JB51.NET/ASDF

Curl: () The requested URL returned error:404

[Root@krlcgcms01 mytest]# Curl HTTP://WWW.JB51.NET/ASDF

。。。。。。。。。。。。

[Root@krlcgcms01 mytest]# curl-f HTTP://WWW.JB51.NET/ASDF

Curl: () The requested URL returned error:404

[Root@krlcgcms01 mytest]# Curl HTTP://WWW.JB51.NET/ASDF

。。。。。。。。。。。。

9, forge the source address, some sites will judge, the request source address.

[Root@krlcgcms01 mytest]# curl-e http://localhost http://www.jb51.net/wp-login.php

[Root@krlcgcms01 mytest]# curl-e http://localhost http://www.jb51.net/wp-login.php

10, when we often use curl to engage in other people's things, people will put your IP shielding, this time, we can use the agent

[Root@krlcgcms01 mytest]# curl-x 24.10.28.84:32779-o home.html http://www.jb51.net

[Root@krlcgcms01 mytest]# curl-x 24.10.28.84:32779-o home.html http://www.jb51.net
11, something larger than that we can segment the download

[Root@krlcgcms01 mytest]# curl-r 0-100-o img.part1 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

0 0 0--:--:----:--:----:--:--0

[Root@krlcgcms01 mytest]# curl-r 100-200-o img.part2 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

100 101 100 101 0 0 57 0 0:00:01 0:00:01--:--:--0

[Root@krlcgcms01 mytest]# curl-r 200--o img.part3 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

104k 104k 0 0 52793 0 0:00:02 0:00:02--:--:--88961

[Root@krlcgcms01 mytest]# ls |grep part | Xargs Du-sh

4.0K One.part1

112K Three.part3

4.0K Two.part2

[Root@krlcgcms01 mytest]# curl-r 0-100-o img.part1 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

0 0 0--:--:----:--:----:--:--0

[Root@krlcgcms01 mytest]# curl-r 100-200-o img.part2 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

100 101 100 101 0 0 57 0 0:00:01 0:00:01--:--:--0

[Root@krlcgcms01 mytest]# curl-r 200--o img.part3 http://www.jb51.net/wp-

Content/uploads/2010/09/compare_varnish.jpg

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

104k 104k 0 0 52793 0 0:00:02 0:00:02--:--:--88961

[Root@krlcgcms01 mytest]# ls |grep part | Xargs Du-sh

4.0K One.part1

112K Three.part3

4.0K Two.part2

Use the time, put them cat just OK, cat img.part* >img.jpg

12, download progress information will not be displayed

[Root@krlcgcms01 mytest]# curl-s-o aaa.jpg

13, Show download progress bar

[Root@krlcgcms01 mytest]# Curl-#-O

######################################################################## 100%

14, download files via FTP

[Zhangy@blackghost ~]$ curl-u Username: password-o http://www.jb51.net/demo/curtain/bbstudy_files/style.css

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

1934 1934 0 0 3184 0--:--:----:--:----:--:--7136

[Zhangy@blackghost ~]$ curl-u Username: password-o http://www.jb51.net/demo/curtain/bbstudy_files/style.css

% total% Received% Xferd Average Speed time

Dload Upload Total spent left Speed

1934 1934 0 0 3184 0--:--:----:--:----:--:--7136

Or in the following way

[Zhangy@blackghost ~]$ curl-o ftp://username: password @ip:port/demo/curtain/bbstudy_files/style.css

[Zhangy@blackghost ~]$ curl-o ftp://username: password @ip:port/demo/curtain/bbstudy_files/style.css

15, upload via FTP

[Zhangy@blackghost ~]$ curl-t test.sql ftp://username: password @ip:port/demo/curtain/bbstudy_files/

[Zhangy@blackghost ~]$ curl-t test.sql ftp://username: password @ip:port/demo/curtain/bbstudy_files/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.