如何使用 wget 從各個鏈接下載多個文件

如何使用 wget 從各個鏈接下載多個文件

假設我有各種想要下載的圖像,並且有可用的連結:

https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80

https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80

我不想一一輸入

wget https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80

wget https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80

我怎樣才能實現這個目標?我讀過,將這些連結保存在 .txt 檔案中並使用 for 循環不是正確的方法。

答案1

如果您的文件中有這樣的 URL:

https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80

然後你就可以跑了

wget --input-file=file

按照@的描述下載圖像善行難陀

答案2

如果你想將所有內容保留在同一個腳本中,--input-file/-i選項也可以讀取stdin

wget -i - << EOF
https://images.unsplash.com/photo-1548363585-5b1241ee3b85?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
https://images.unsplash.com/photo-1556648011-e01aca870a81?ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80
EOF

相關內容