Bash脚本下载示例

我们将需要两个文件:一个名为“download.sh”的文件,其中包含我们的bash脚本,另一个“urls.txt”,其中包含我们想要下载的文件的URL列表。

showsload.sh里面:

#!/bin/bash
while read url; do
    wget $url
done < urls.txt

在“URLS.txt”中,放入要下载的文件列表:

http://example.com/file1.tar
http://example.com/file2.tar
http://example.com/file3.tar

赋予文件执行权限并运行脚本:

$chmod +x download.sh
$./download.sh

或者使用curl:

#!/bin/bash
while read url; do
    curl $url -O
done < urls.txt

如何使用WGet下载文件

WGET下载文件的基本语法非常简单:

$wget http://example.com/file.tar

如果要指定要保存文件的位置,则可以使用命令中的“-o”(输出)选项。

$wget http://example.com/file.tar -O /path/to/dir/file.tar
在Linux上使用命令行从URL下载文件

如何用curl下载文件

默认情况下,CURL将将文件下载到标准输出。
使用-o(输出)选项指定文件的保存位置。

curl http://example.com/file.tar -o /path/to/dir/file.tar
日期:2020-07-07 20:56:06 来源:oir作者:oir