0

How can I download multiple files using wget? I also want to rename the files. Here are the commands I'm running one by one (copy/paste on terminal):

    wget -c --load-cookies cookies.txt http://www.filesonic.com/file/812720774/PS11.rar -O part11.rar
    wget -c --load-cookies cookies.txt http://www.filesonic.com/file/812721094/PS12.rar -O part12.rar
    wget -c --load-cookies cookies.txt http://www.filesonic.com/file/812720804/PS13.rar -O part13.rar
    wget -c --load-cookies cookies.txt http://www.filesonic.com/file/812720854/PS14.rar -O part14.rar
........ and so on..

What can I do to download all these files one by one?

slhck
  • 235,242
coure2011
  • 1,679

1 Answers1

2

You probably want a short shell script like this:

#!/usr/bin/env bash
while read line
do
  wget -c --load-cookies cookies.txt $line -O ${line##*/}
done < filelist

Where filelist is a text file that contains each download link, one by one. ${line##*/} will extract the filename itself and therefore produce something similar to the following commands:

wget -c --load-cookies cookies.txt http://download/file1.rar -O file1.rar
wget -c --load-cookies cookies.txt http://download/file2.rar -O file2.rar
wget -c --load-cookies cookies.txt http://download/file3.rar -O file3.rar

If you want to run these in parallel, you can also just wrap the wget line inside parentheses to run it in a subshell.

(wget -c --load-cookies cookies.txt $line -O ${line##*/})

Or add an ampersand. This would however mean that the downloads will still run when you cancel the script. You'd have to kill them manually for each process.

wget -c --load-cookies cookies.txt $line -O ${line##*/} &
slhck
  • 235,242