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.


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

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


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.

  • 1
    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 '10 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 '10 at 21:11
  • This works with --no-directories as well. – CMCDragonkai Feb 10 '17 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy