Tuesday, August 19, 2008

Wget

Wget is basically a command line way to download things. I typically use it with the -O option which I have outlined below. See the sources for more options.

Using the "-O" option. This allows you to download a file to where you want on your system, rather than just in your home directory. With this option only, if you download a duplicate file, the older file will be overwritten.
Example: wget -O /path/to/file URL
(Note that URL is the full URL of the file on the web)

Using the "-r" option. With this option, a file will be downloaded on your system by duplicating its native folder structure. Try it out and you will see what I mean.
Example: wget -r URL

These options can, of course, be combined. A few rules I found confusing involved the following combinations listed below. These involve a situation where you are downloading a file that you had previously downloaded:

If no options are specified = Wget will not overwrite the previous file with the same name, but will simply download the new file adding a number to it. So if your original file is named cookie, if you download it again, it will be named cookie.1. If you download it a third time, it will be named cookie.2.


If you only use the "-nc" option = Wget will refuse to download newer copies of the file.

If you only use the "-r" option = re-downloading a file will result in the new copy simply overwriting the old. However, as noted, it will be downloaded in folders replicating its location on the web.

If you use both "-r" and "-nc" =
this causes the original version to be preserved and any newer copies on the server to be ignored (similar to only using the "-nc" option).

Therefore, I usually just use the "-O" option as described above so that a previous file of the same name can be overwritten and I avoid the extra folders.

Sources: Wget man page

No comments: