带有示例Linux curl命令教程

Simply curl or command-line tool and library for transferring data with URLs. curl provides a wide range of support to download files and folders with a command-line interface. curl can be used with a lot of different types of protocols. Below are the protocols currently supported by the curl.

只需使用curl或命令行工具和库即可通过URL传输数据。 curl通过命令行界面为下载文件和文件夹提供了广泛的支持。 curl可以用于许多不同类型的协议。 下面是curl当前支持的协议。

  • DICT

    信息通信技术
  • FILE

    文件
  • FTP/FTPS

    FTP / FTPS
  • Gopher

    地鼠
  • HTTP

    HTTP
  • HTTPS

    HTTPS
  • IMAP/IMAPS

    IMAP / IMAPS
  • LDAP/LDAPS

    LDAP / LDAPS
  • POP3/POP3S

    POP3 / POP3S
  • RTMP

    RTMP
  • RTSP

    RTSP
  • SCP

    SCP
  • SFTP

    SFTP
  • SMB

    中小型企业
  • SMTP/SMTPS

    SMTP / SMTPS
  • Telnet and TFTP

    Telnet和TFTP
  • SSL certificates

    SSL证书
  • HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos), file transfer resume, proxy tunneling

    HTTP POST,HTTP PUT,FTP上传,基于HTTP表单的上传,代理,HTTP / 2,cookie,用户+密码验证(基本,普通,摘要,CRAM-MD5,NTLM,协商和Kerberos),文件传输恢复,代理隧道

Keep your breath because there are a lot of examples about curl where we look at them one by one.

屏住呼吸,因为有很多关于卷曲的例子,我们会一一看待。

curl命令语法 (curl Command Syntax)

The syntax of the curl command is like below.

curl命令的语法如下。

curl [options...] <url>

卷曲命令人 (curl Command Man)

Man page of curl can get with the following command

curl的手册页可以通过以下命令获取

$ man curl
Man
Man

curl命令帮助(curl Command Help)

Simple fast help about parameters and options can get with the following command.

使用以下命令可以获得有关参数和选项的简单快速帮助。

$ curl -h
Help
Help
帮帮我

使用HTTP和HTTPS连接获取和显示(Fetch And Display with HTTP and HTTPS Connections)

One of the most used types of curl is downloading HTML or similar files with HTTP/s. curl will automatically detect the transfer protocol which is HTTPs in this example.

卷曲的最常用类型之一是使用HTTP / s下载HTML或类似文件。 在此示例中,curl将自动检测传输协议,即HTTP。

$ curl https://www.poftut.com
Fetch And Display with HTTP/s
Fetch And Display with HTTP/s
使用HTTP / s进行获取和显示

使用HTTP / s下载并重定向(Download with HTTP/s and Redirect)

In the previous example, the downloaded file is printed out the standard output which is our terminal. But this is generally not a practical usage. The downloaded file can be redirected to a file with a bash redirect feature like below. In this example, we can see some statistical information about the download. This information provides total size, received, average download speed, total time and times spend for download.

在前面的示例中,下载的文件被打印出标准输出,这是我们的终端。 但这通常不是实际用法。 可以使用如下所示的bash重定向功能将下载的文件重定向到文件。 在此示例中,我们可以看到有关下载的一些统计信息。 该信息提供了总大小,已接收,平均下载速度,总时间和花费的下载时间。

$ curl https://www.poftut.com > poftut.html
Download with HTTP/s and Redirect
Download with HTTP/s and Redirect
使用HTTP / s下载并重定向

以HTTP / s下载(Download with HTTP/s)

There is a parameter used to save the downloaded file into a file with no extra command. This parameter is -o

有一个参数可用于将下载的文件保存到文件中,而无需任何额外的命令。 此参数是-o

$ curl -o poftut.html https://www.poftut.com
Download with HTTP/s
Download with HTTP/s
以HTTP / s下载

限制下载率(Limit Download Rate)

Another useful feature of curl is limiting download rate. This can be very useful in situations where there is limited internet bandwidth and it should be shared with other applications. In this examples, we have limited bandwidth to 1K and this will make our download take some time

curl的另一个有用功能是限制下载速度。 这在Internet带宽有限的情况下非常有用,应该与其他应用程序共享。 在此示例中,我们将带宽限制为1K,这将使我们的下载花费一些时间

$ curl --limit-rate 1k -o poftut.html https://www.poftut.com
Limit Download Rate
Limit Download Rate
限制下载率

下载顺序文件(Download Sequential Files)

System administrators generally prefer using sequential file names for backups or similar operations. Also log files that reside in /var/log are generally names with sequentially. So downloading them one by one specifying the full name of the file is drudgery work. curl can download these files like the following example.

系统管理员通常更喜欢使用顺序文件名进行备份或类似操作。 同样,驻留在/var/log中的日志文件通常是按顺序命名的名称。 因此,一一指定文件的全名下载它们是繁琐的工作。 curl可以像以下示例一样下载这些文件。

$ curl  ftp://www.poftut.com/backup[1-9].tar

设置HTTPS的SSL版本 (Set SSL Version For HTTPS)

While using secure protocols like HTTPS, FTPS, POP3S SSL protocol will be used to create encrypted channels. SSL has a different version where this may create incompatible situations. SSL version can be specified with the --sslv2 and--sslv3 parameter. But keep in mind that curl uses GnuTLS library for cryptographic operations and GnuTLS should have support for SSLv2.

使用HTTPS,FTPS,POP3S SSL等安全协议时,将使用SSL协议创建加密通道。 SSL的版本不同,这可能会导致不兼容的情况。 可以使用--sslv2--sslv3参数指定SSL版本。 但是请记住,curl使用GnuTLS库进行加密操作,并且GnuTLS应该支持SSLv2。

$ curl --sslv2 -o poftut.html https://www.poftut.com
Set SSL Version
Set SSL Version
设定SSL版本

详细和调试模式(Verbose and Debug Mode)

While downloading and uploading files with curl there will be operations that occur background. There will be also problems that we can not know what is happening. curl can provide details about the operations with the -v parameter like below.

在使用curl下载和上传文件时,会有一些操作在后台进行。 还有一些我们不知道发生了什么的问题。 curl可以使用-v参数提供有关操作的详细信息,如下所示。

$ curl --ssl -v -o poftut.html https://www.poftut.com
Verbose and Debug Mode
Verbose and Debug Mode
详细和调试模式

静音模式(Silent Mode)

There is another mode where there will be no output to the terminal. This can be used for clean download.

还有另一种模式,其中不会有任何输出到终端。 这可以用于全新下载。

$ curl -s -o poftut.html https://www.poftut.com

指定用户名和密码 (Specify User and Password)

While using authentication required protocols and servers curl can provide these credentials like username and password.

在使用身份验证所需的协议和服务器时,curl可以提供这些凭据,例如用户名和密码。

$ curl -u ismail:mypassword -o data.tar ftp://poftut.com/backup.tar

设置Cookie进行连接 (Set Cookie For Connection)

As we know HTTP is a stateless protocol. To preserve user session cookies are used. While using HTTP protocol existing cookies can be used with -b parameter like below.

众所周知,HTTP是无状态协议。 为了保留用户会话cookie。 在使用HTTP协议时,现有的cookie可以与-b参数一起使用,如下所示。

$ curl -b aerf34fawfeawf -o statistics.html https://www.poftut.com/statistics.html
LEARN MORE  Best SFTP or SCP Clients For Windows Operating Systems
了解更多Windows操作系统的最佳SFTP或SCP客户端

翻译自: https://www.poftut.com/linux-curl-command-tutorial-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值