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

DownloadWget

Download Problem Overview


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

Download Solutions


Solution 1 - Download

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]

Solution 2 - Download

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.

Solution 3 - Download

You would use the command Mechanical snail listed. Notice the uppercase O. Full command line to use could be:

wget www.examplesite.com/textfile.txt --output-document=newfile.txt

or

wget www.examplesite.com/textfile.txt -O newfile.txt

Hope that helps.

Solution 4 - Download

wget -O yourfilename.zip remote-storage.url/theirfilename.zip

will do the trick for you.

Note:

a) its a capital O.

b) wget -O filename url will only work. Putting -O last will not.

Solution 5 - Download

Either curl or wget can be used in this case. All 3 of these commands do the same thing, downloading the file at http://path/to/file.txt and saving it locally into "my_file.txt":

wget http://path/to/file.txt -O my_file.txt  # my favorite--it has a progress bar
curl http://path/to/file.txt -o my_file.txt
curl http://path/to/file.txt > my_file.txt

Notice the first one's -O is the capital letter "O".

The nice thing about the wget command is it shows a nice progress bar.

You can prove the files downloaded by each of the 3 techniques above are exactly identical by comparing their sha512 hashes. Running sha512sum my_file.txt after running each of the commands above, and comparing the results, reveals all 3 files to have the exact same sha hashes (sha sums), meaning the files are exactly identical, byte-for-byte.

See also: https://stackoverflow.com/questions/13735051/how-to-capture-curl-output-to-a-file/69411327#69411327</sub>

Solution 6 - Download

Using CentOS Linux I found that the easiest syntax would be:

wget "link" -O file.ext

where "link" is the web address you want to save and "file.ext" is the filename and extension of your choice.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnoobcoderView Question on Stackoverflow
Solution 1 - DownloadnaumchoView Answer on Stackoverflow
Solution 2 - DownloadmousomerView Answer on Stackoverflow
Solution 3 - DownloadioMatrixView Answer on Stackoverflow
Solution 4 - DownloadLakshman PilakaView Answer on Stackoverflow
Solution 5 - DownloadGabriel StaplesView Answer on Stackoverflow
Solution 6 - DownloadZenkyGtView Answer on Stackoverflow