bash 使用自定义文件名同时(并行)下载多个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20156931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Download multiple files simultaneously (parallel) with custom filenames
提问by octosquidopus
In a bash script, I am trying to download multiple files in parallel, with custom filenamesusing a singlecommand (no loops).
在bash脚本,我想下载多个文件并行,与自定义文件名使用一个命令(没有循环)。
I tried using aria2c:
我尝试使用 aria2c:
aria2c -j2 URL1 URL2 # BAD: outputs to a single file
aria2c -j2 -Z URL1 -o 1 URL2 -o 2 # BAD: filenames taken from link (-o is ignored)
The second one ignores the output filename because, quoting the aria2c manpage:
第二个忽略输出文件名,因为引用了 aria2c 联机帮助页:
In Metalink or BitTorrent download you cannot specify file name. The file name specified here is only used when the URIs fed to aria2 are done by command line without --input-file, --force-sequential option. For example:
$ aria2c -o myfile.zip "http://example1.com/file.zip" "http://example2.com/file.zip"
在 Metalink 或 BitTorrent 下载中,您不能指定文件名。此处指定的文件名仅在提供给 aria2 的 URI 由命令行完成而没有 --input-file, --force-sequential 选项时使用。例如:
$ aria2c -o myfile.zip " http://example1.com/file.zip" " http://example2.com/file.zip"
This is what I want to avoid:
这是我想要避免的:
aria2c URL1 -o 1 &
aria2c URL2 -o 2 &
aria2c URL3 -o 3 # BAD: slow and ugly, because aria2c is called thrice
Any suggestions?
有什么建议?
回答by ArtemB
Aria2c supports getting URIs from a file.
Try writing your file names into the file and then running "aria2c -i uri-list.txt" or write them to stdout and pipe them to "aria2c -i -"
尝试将您的文件名写入文件,然后运行“aria2c -i uri-list.txt”或将它们写入标准输出并通过管道将它们传送到“aria2c -i -”
回答by gulp79
with -Z option:
使用 -Z 选项:
-Z, --force-sequential[=true|false] Fetch URIs in the command-line sequentially and download each URI in a separate session, like the usual command-line download utilities.
so in your case:
所以在你的情况下:
aria2c -Z URL1 URL2 URL3 URL4