curl command - file transfer tool

The curl command is the abbreviation of the English phrase "CommandLine URL". It is the work of file transfer based on URL rules in the Shell terminal, including file upload and download. The supported protocols include more than 30 common protocols such as HTTP, HTTPS, and FTP.

Another powerful download command is wget, see https://blog.csdn.net/u013007181/article/details/129458534 for details

The syntax of the curl command is as follows:

curl [选项] 网址

Commonly used options are as follows:

options role or meaning
-o   Download the file and rename the downloaded file to the new filename
-O Download the file without changing the original file name of the downloaded file
-u Specify the username and password to log in to the server 
-I Uppercase i, print HTTP response header information 
-A Send user agent information to the server 
-s Silent mode, do not output any information 
-T upload files

Example demonstration

1. View the source code of the website

[root@myEuler ~]# curl https://www.baidu.com
<!DOCTYPE html>
……此处省略部分输出……

2. Download the file and keep the original file name

[root@myEuler ~]# curl -O http://10.200.7.88/k8s/docker-20.10.23.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 62.9M  100 62.9M    0     0  47.4M      0  0:00:01  0:00:01 --:--:-- 47.4M

#查看下载的文件
[root@myEuler ~]# ls docker-20.10.23.tgz 
docker-20.10.23.tgz

3. Download the file and rename it to the new file name

[root@myEuler ~]# curl -o docker http://10.200.7.88/k8s/docker-20.10.23.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 62.9M  100 62.9M    0     0  47.4M      0  0:00:01  0:00:01 --:--:-- 47.4M

#查看下载的文件
[root@myEuler ~]# ls docker
docker

4. Print HTTP response header information

[root@myEuler ~]# curl -I http://192.168.18.18
HTTP/1.1 200 OK
Server: nginx/1.21.5
Date: Fri, 10 Mar 2023 14:08:52 GMT
Content-Type: text/html
Content-Length: 94924
Last-Modified: Thu, 09 Mar 2023 01:44:31 GMT
Connection: keep-alive
ETag: "640939ff-172cc"
Accept-Ranges: bytes

5. Use user account to download files

# 指定用户名zhangsan和密码,从指定站点下载文件
[root@myEuler ~]# curl -u zhangsan:Mima1234! -so docker2 ftp://192.168.218.115/docker

# 查看下载的文件
[root@myEuler ~]# ls docker2 
docker2

Guess you like

Origin blog.csdn.net/u013007181/article/details/129453538