Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget command to download a file and save as a different filename

Tags:

download

wget

I am downloading a file using the wget command. But when it downloads to my local machine, I want it to be saved as a different filename.

For example: I am downloading a file from www.examplesite.com/textfile.txt

I want to use wget to save the file textfile.txt on my local directory as newfile.txt. I am using the wget command as follows:

wget www.examplesite.com/textfile.txt 
like image 798
noobcoder Avatar asked May 21 '13 20:05

noobcoder


People also ask

How do I specify a filename in wget?

Save with different file name By default, downloaded file will be saved with the last name mentioned in the URL. To save file with a different name option O can be used. Syntax: wget -O <fileName><URL>

Will wget overwrite files?

If you specify the output file using the -O option it will overwrite any existing file.

How do I download multiple files from wget?

If you want to download multiple files at once, use the -i option followed by the path to a local or external file containing a list of the URLs to be downloaded. Each URL needs to be on a separate line. If you specify - as a filename, URLs will be read from the standard input.


2 Answers

Use the -O file option.

E.g.

wget google.com ... 16:07:52 (538.47 MB/s) - `index.html' saved [10728] 

vs.

wget -O foo.html google.com ... 16:08:00 (1.57 MB/s) - `foo.html' saved [10728] 
like image 118
naumcho Avatar answered Oct 08 '22 00:10

naumcho


Also notice the order of parameters on the command line. At least on some systems (e.g. CentOS 6):

wget -O FILE URL 

works. But:

wget URL -O FILE 

does not work.

like image 42
mousomer Avatar answered Oct 08 '22 00:10

mousomer