Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
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{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

Your Answer


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