Linux wget命令和curl命令
1. wget命令:下载文件
基本语法
wget
命令用于从网络下载文件。基本的wget语法如下:
wget [选项] [URL]
例如,要下载一个名为example.zip
的文件,可以运行:
wget https://example.com/files/example.zip
常用选项
-P
:指定保存文件的目录。-O
:指定下载文件的保存名称。-c
:继续中断的下载。-r
:递归下载整个目录。
示例:
- 下载文件并保存为指定名称:
wget -O myfile.zip https://example.com/files/file.zip
- 下载文件到指定目录:
wget -P /path/to/directory https://example.com/files/file.zip
2. curl命令:发起网络请求
基本语法
curl
命令用于发起HTTP请求并显示服务器的响应。基本的curl语法如下:
curl [选项] [URL]
例如,要从服务器获取网页内容,可以运行:
curl https://example.com
常用选项
-o
:指定将响应保存到文件。-O
:将响应保存到与URL中的文件名相同的文件。-I
:仅显示响应头部信息。-X
:指定HTTP请求方法(GET、POST等)。
示例:
- 将响应保存到文件:
curl -o output.html https://example.com/page.html
- 获取文件并保存为与URL中的文件名相同的文件:
curl -O https://example.com/files/file.txt