1

I'm downloading files from a POST endpoint using a command on the form

while true; do curl -O -J http://domain/endpoint; done

This endpoint "returns" a new file on each POST call. Curl gives each file the filename given by the Content-Disposition header.

The problem is that the server gives the same filename for several of the files. Are there any easy ways to append a postfix to the filename, e.g. use "filename_1.pdf" instead of "filename.pdf" if a file named "filename.pdf" already exists in the folder?

  • Use wget instead? – muru Jul 13 '17 at 10:45
  • As far as I know wget always appends .1, .2, etc. to the filename if it already exists in the folder. This is a problem because on Windows a pdf.1 file (for example) won't be recognized as a PDF file. Do you know of a way to make wget use filenames on the form _1.pdf instead of pdf.1? – haroba Jul 13 '17 at 10:57
  • IMO its easier to do batch rename after you already have the numbers than to manually kludge up numbering yourself. Say, something like rename -n 's/pdf.(\d+)$/$1.pdf/' *.pdf.* after downloading. – muru Jul 13 '17 at 11:00

Your Answer

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

Browse other questions tagged or ask your own question.