问题,下载多个文件,其名称以BASH表示

问题描述 投票:1回答:1

我正在尝试使用xargs并行下载多个文件。如果我只下载没有给定名称的文件,那么一切都会很好地进行。 echo ${links[@]} | xargs -P 8 -n 1 wget。有什么方法可以让我像wget -O [filename] [URL]这样的文件名但可以并行下载?以下是我的工作。谢谢。

links=(
    "https://apod.nasa.gov/apod/image/1901/sombrero_spitzer_3000.jpg"
    "https://apod.nasa.gov/apod/image/1901/orionred_WISEantonucci_1824.jpg"
    "https://apod.nasa.gov/apod/image/1901/20190102UltimaThule-pr.png"
    "https://apod.nasa.gov/apod/image/1901/UT-blink_3d_a.gif"
    "https://apod.nasa.gov/apod/image/1901/Jan3yutu2CNSA.jpg"
)

names=(
    "file1.jpg"
    "file2.jpg"
    "file3.jpg"
    "file4.jpg"
    "file5.jpg"
) 

echo ${links[@]} ${names[@]} | xargs -P 8 -n 1 wget
shell file download xargs
1个回答
0
投票

使用GNU Parallel,您可以做:

parallel wget -O {2} {1} ::: "${links[@]}" :::+ "${names[@]}"

如果下载失败,GNU Parallel也可以使用--retry 3重试命令。

© www.soinside.com 2019 - 2024. All rights reserved.