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.

    FYI, This information is available in `man wget`

    @user606723 Can you explain why this got downvotes? It's a legitimate question.

    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.

    This SO Q&A explains that you can do this using the `-P` switch, same w/ the A below. From the manual page: How to specify the location with wget?.

    This is only a basic question to those who already know the answer. To anyone who doesn’t, it is *not* basic. Searching the man pages is not as simple as it sounds because they are quite long and few sane people with lives have the time or wherewithal to sit and read through all of that. The best argument you can make is that the man pages could be filtered with `grep` or something, but even that is not likely to give the answer due to wording.

  • Tim Kennedy

    Tim Kennedy Correct answer

    9 years ago

    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

    @jrg: You *can* specify a download directory. See ephemient's answer.

    right is that -0 or -O, I guess can just copy it and see

    its a `minus capital O` if that helps

    askubuntu's answer sets a new default (with alias in `.bashrc`) without needing to type the command each time: how to change wget default directory

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM