2

How do I use wget to download files to a specific location, without creating directories, and overwrite the original every time.

I've tried using the -r -P and nc options in combination but this resulted in several undesirable effects.

wget -P ./temp -r "https://raw.githubusercontent.com/octocat/Spoon-Knife/master/README.md" -nd

The above downloads README.md to the /temp directory in the current folder, but preserves the original README.md and numbers all subsequent README.md files.

wget -r -P ./temp "https://raw.githubusercontent.com/octocat/Spoon-Knife/master/README.md" -nd

Above command does the same thing.

wget -P ./temp -nc "https://raw.githubusercontent.com/octocat/Spoon-Knife/master/README.md" -r

With this one, the file is replaced but directories are created.

1

You can achieve the required result in wget (or curl) by specifying an output document.


With wget:

wget https://raw.git...etc.../README.md -O ./temp/README.md


With curl:

curl https://raw.git...etc.../master/README.md > ./temp/README.md
3
  • This answer does not match the question's criteria: download to a specified location, download files without creating directories, and overwrite the original files every time. – Enkouyami Apr 25 '15 at 19:07
  • The question specifies the file must be overwritten each time and no folders must be created.. Specifying the original file as output each time achieves this. How does the above not match your requirements? – toxefa Apr 25 '15 at 19:11
  • 1
    Sorry, I misread something, they work perfectly. – Enkouyami Apr 25 '15 at 19:27
0

Saving file content to output file won't work with binary files.

I observed that only files that contains extension (have . in their name) are downloaded in a new folder with the same name:

For example, wget 2 files: my_archive.zip and no_extension_file using commands:

    wget -P ~/Downloads/no_extension_file https://<IP>/no_extension_file
    wget -p ~/Downloads/my_archive.zip https://<IP>/my_archive.zip

will result in:

   ~/Downloads/no_extension_file
   ~/Downloads/my_archive.zip/my_archive.zip 

Your Answer

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

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