Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
FYI, This information is available in man wget –  user606723 Oct 28 '11 at 16:28
@user606723 Can you explain why this got downvotes? It's a legitimate question. –  jrg Oct 31 '11 at 12:29
it's my guess that it was down voted because this is an extremely basic question and would've been solved by any sort of googling or looking in man get. The goal of stackexchange isn't to answer every possible question. –  user606723 Dec 11 '11 at 22:38

2 Answers 2

up vote 9 down vote accepted

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, but you can't just specify a directory.

wget -O /var/cache/foobar/stackexchange-site-list.txt http://url.to/stackexchange-site-list.txt
share|improve this answer
Thanks for your answer! –  jrg Oct 28 '11 at 17:22
@jrg: You can specify a download directory. See ephemient's answer. –  unor Nov 27 '12 at 16:32
wget -P /var/cache/foobar/ [...]
wget --directory-prefix=/var/cache/foobar/ [...]
share|improve this answer
-P lets wget start creating sub folders depending on how you select options to download. –  Kendrick Apr 28 '14 at 15:07
-P seems to be the synonym for --directory-prefix. From the manual: ‘-P prefix’ ‘--directory-prefix=prefix’ Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree. The default is ‘.’ (the current directory). –  Engineer Dollery Feb 20 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.