代码之家  ›  专栏  ›  技术社区  ›  sisanared

wget并行下载文件并重命名

  •  3
  • sisanared  · 技术社区  · 7 年前

    我有一个包含两列的文本文件:第一列是要保存为的名称,第二列是资源的URL地址。

    10000899567110806314.jpg 'http://lifestyle.inquirer.net/files/2018/07/t0724cheekee-marcopolo_1-e1532358505274-620x298.jpg'
    10001149035013559957.jpg 'https://www.politico.eu/wp-content/uploads/2018/07/GettyImages-1004567890.jpg'
    10001268622353586394.jpg 'http://www.channelnewsasia.com/image/10549912/16x9/991/529/a7afd249388308118058689b0060a978/Zv/tour-de-france-5.jpg'
    10001360495981714191.jpg 'https://media.breitbart.com/media/2018/07/Dan-Coats.jpg'
    

    这个文件包含数千行,所以我想快速下载和重命名这些图像。

    我在SO上阅读了多篇文章,并提出了这个解决方案:

    cat list.txt  | xargs -n 1 -P 4 -d '\n' wget -O 
    

    哪些用途 xargs 并行下载。我想用 wget 具有 -O 选项重命名下载的文件。当我开单人间的时候 WGET 命令,这很有效。例子:

    wget -O 10000899567110806314.jpg 'http://lifestyle.inquirer.net/files/2018/07/t0724cheekee-marcopolo_1-e1532358505274-620x298.jpg'
    

    但是,当使用xargs并行下载命令时,我会得到以下错误:

    Try `wget --help' for more options.
    wget: missing URL
    Usage: wget [OPTION]... [URL]...
    

    如果我生成一个只有(单列)换行符分隔的URL的文件,并运行以下命令,它会很好地工作。

    cat list.txt  | xargs -n 1 -P 4 -d '\n' wget
    

    但是,我不想先下载文件,然后再执行重命名操作。

    1 回复  |  直到 7 年前
        1
  •  2
  •   nbari    7 年前

    -n 1

    cat list.txt | xargs -n 2 -P 4 wget -O
    

    -L 1

    xargs < list.txt -P 4 -L 1 wget -O
    

     -L number
         Call utility for every number non-empty lines read. 
         A line ending with a space continues to the next non-empty line. 
         If EOF is reached and fewer lines have been read than number then utility 
         will be called with the available lines.  The -L and -n options are
         mutually-exclusive; the last one given will be used.
    
    推荐文章