wget: saving a file to a custom location
This will be a really quick post which will be obvious to unix sysadmin veterans but hopefully will be helpful to us mere mortals…
wget is a linux/*nix command line tool which can download files (including entire websites if options are set correctly) and at first glance, from looking at the wget man page you’d be forgiven for thinking there was no way to save the file wget downloads to a custom location and for multiple files, you pretty much be right (though you could pipe the output of wget to another program but that’s another story).
By default, wget saves files to the current directory so if you’re writing a script which uses wget (as I did yesterday), you may want to specify a path for the file to be downloaded to. The good news is that you can do this for single files very easily using the -O (capital o) parameter which in the man page says e.g.:
wget -O /home/user1/wp.tgz http://wordpress.org/latest.tar.gz
This will save the latest WordPress tarball to the directory /home/user1 and call the file wp.tgz. Simple!
NOTE: This only works for single files since the -O option concatenates all downloaded files into one file.
See the wget man page for further info on other options.
| This entry was posted by Neil Craig on August 19, 2010 at 7:35 pm, and is filed under General Web-Development, Sysadmin. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 1 year ago
Or just use -P:
-P, –directory-prefix=PREFIX save files to PREFIX/…
about 5 months ago
Thank you! Your post was very useful for me.
Just to remember: We can’t concatenate (-O) with (-N) option. -N checks if the file that we are downloading is more recent than the one we have local.
Gerard’s comment (-P) works here.