Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do


and it downloads the following file:


How can I make it save as the following?

share|improve this question
A quick note: wget does not do image conversion. Saving a GIF file with a .png extension does not turn it into a PNG file. You'll want to save the file with the proper extension (in this case, .gif), and use image manipulation software to convert it to a different format. – Indrek Aug 4 '12 at 16:17
An image is a file. – Andrew J. Brehm Aug 4 '12 at 21:37
up vote 40 down vote accepted

Why does wget choose this name?

Unfortunately, wget will make no assumptions about what you want to download unless you tell it to. It doesn't care if your file is an image, a document, a zipped file, et cetera.

The file is saved as whatever the URL ended with – so anything from the last slash to the end of the URL. In your case, that's .gif?id=2. The part after the actual file extension (.gif) is contained in the URL, but it's a HTTP query parameter. For wget, however, it will determine the output filename.

How can I set a different filename?

If you want to specify an output filename for wget, add the -O (uppercase O) option:

wget -O 2.gif

This will override the default behavior and set the filename to 2.gif. Note that the -o (downcase) option specifies the output filename for any log messages wget might otherwise print to the shell.

Finally, there's the --content-disposition option which might result in the proper filename being set. But this entirely depends on the server you're downloading from sending the correct header information:

This option is useful for some file-downloading CGI programs that use Content-Disposition headers to describe what the name of a downloaded file should be.

The option is currently still marked as experimental and thus not enabled by default.

I strongly encourage you to read the manpage of the tools you're using to understand their behavior. Just enter man wget and read through it, especially the options it provides.

Also, to address what @Indrek wrote in the comment on your question: I assume you have a typo there and don't mean to download a GIF file into a file called .png — just changing the extension will not automatically make it a PNG. GIF and PNG use different encodings and you will have to use any kind of image conversion tool to convert between these formats. This conversion, however, will be lossless, so there's no harm done in downloading the files in the "wrong" format and converting later.

share|improve this answer
I have no idea why this has so many up votes, because the URL you posted is for a .gif file, changing the file name to 2.png will not magically make that .gif a .png. Either way an image is a file, everything saved anywhere is a file even directories are actually stored on filesystems as files. – Jarrod Roberson Aug 4 '12 at 22:30
Jarrod, I now updated my answer and explicitly addressed what probably was a misunderstanding by the OP. As for you asking why this answer had so many up votes – are you inferring it should have been downvoted because I gave the OP wrong information? I never claimed that an image was not a file and that a GIF would magically turn into a PNG when renamed. I assumed it was a typo since the focus of the question was the file name. – slhck Aug 4 '12 at 23:02
+1: Cause he's slick. – surfasb Aug 5 '12 at 2:25

There is the command line option --content-disposition which - if the website supplies a correct header - should cause your file to be saved with the right name.

My debian squeeze box it says the option is "experimental" though...

share|improve this answer
Nice find, I missed that before. It doesn't work in this case, but it could in others. – slhck Aug 4 '12 at 22:12
@slhck Yes, noticed that too - after writing it. But since it might work for others I left it :) – dualed Aug 4 '12 at 22:28

This is simply because look at the path, it ends in ?id=2, therefore it will save as this, you can move the file or use the -O parameter to define a file name.

share|improve this answer

If the file you direct wget to download for you is indeed an image, then what it downloads is an image. wget doesn't bother to guess the correct file name and extension, it uses what it finds in the URL e.g you might get something like photo.php?n=cat.png but it is still an image. To fix your problem, simply rename that file to the correct name cat.png. Note that on most operating systems programs need the correct file extension to know that they can open a given file.

share|improve this answer

Also, with curl, say you don't know what the filename is going to be, due to redirects, or whathaveyou.. just follow the redirects via -L and pipe it to a file, with the correct extension..

curl -L > /files/file.png

wget may have similar functionality, dunno.

share|improve this answer
Why the downvote? It works, and solves the guys' problem, no? – mralexgray Aug 5 '12 at 8:12
I didn't downvote but you clearly haven't read the question. – nikhil Aug 5 '12 at 12:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .