How to rename files specifically in a list that wget will use

wget

I have a file with a list of links to some youtube videos.

When I run the command:

wget -i list

Everything works just fine, however wget is automatically renaming the files to the gibberish at the end of each link. Running wget manually is not an option because there are far too many links. How do I go about giving a custom name to the links that wget will recognize?

Best Answer

The -O option allows you to specify the destination file name. But if you're downloading multiple files at once, wget will save all of their content to the file you specify via -O. Note that in either case, the file will be truncated if it already exists. See the man page for more info.

You can exploit this option by telling wget to download the links one-by-one:

while IFS= read -r url;do
    fileName="blah" # Add a rule to define a new name for each file here
    wget -O "$fileName" "$url"
done < list

You can also take JJoao's suggestion and add a file name next to each URL in the file then do:

while IFS= read -r url fileName;do
    wget -O "$fileName" "$url"
done < list

where it is assumed you have added a (unique) file name after each URL in the file (separated by a space).

Related Question