7

I'm trying to download multiple files and need to rename as I download, how can I do that and specify the directory I want them to download to? I know i need to be using -P and -O to do this but it does not seem to be working for me. I'm writing this into a php script and running on unix.

1 Answer 1

7

You have to either specify the -P or the -O, for example:

wget --directory-prefix="/home/admin/" http://someurl

OR

wget --output-document="/home/my_new_file_name" http://someurl

In the first example it will download anything you want to the specified directory and at the 2nd example it will download the file with the new given name to the given directory.

3
  • 2
    You may also want to look at curl and the -o and --create-dirs options; there's ways to dynamically specify the filenames based on portions of the URL being fetched. For example: "curl http://www.example.com/{foo,bar}.html -o 'example_#1.txt'" will create example_foo.txt and example_bar.txt.
    – freiheit
    Aug 4, 2010 at 20:56
  • i also agree with freiheit, if you have curl available it is probably your best option since you are doing it with a php script.
    – Prix
    Aug 4, 2010 at 21:11
  • This works with --no-directories as well. Feb 10, 2017 at 10:44

You must log in to answer this question.