Download using wget to a different directory than current directory

I need to use wget to download a file to the directory /var/cache/foobar/ (so, as an example, if I download stackexchange-site-list.txt, it’d be downloaded to /var/cache/foobar/stackexchange-site-list.txt)

Is this possible? curl would also be an option, but I’d prefer to not use curl, since it’s not installed by default.

Asked By: jrg

||

If you know the name of the file ahead of time, you can use the -O option to wget to tell it where to write the file.

wget -O /var/cache/foobar/stackexchange-site-list.txt http://url.to/stackexchange-site-list.txt
Answered By: Tim Kennedy
wget -P /var/cache/foobar/ [...]
wget --directory-prefix=/var/cache/foobar/ [...]
Answered By: ephemient
wget -e robots=off -r --no-parent /home/user/Desktop/MIT/ http://abc.tamu.edu/projects/tzivi/repository/revisions/2/raw/tzivi/

To add: The above code would allow you to download ALL files from the targeted directory to the directory of your choice in a single command.

Break Down of Command:

The Parameters for which wget uses to download the entire directory at once instead of one file at a time:

wget -e robots=off -r --no-parent

The Destination of Downloaded Files

/home/user/Desktop/MIT/

The Origin of Files (Online Directory)

http://abc.tamu.edu/projects/tzivi/repository/revisions/2/raw/tzivi/
Answered By: Adamplex
Categories: Answers Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.