Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there any way to tell curl not to download a file when it does not exist on the server?

I am using my Mac OS X shell to download a few files with curl.

The command goes:

curl -s -# "http://URL/session[1-12].pdf" -o "Slides/session#1.pdf";

Is there any way I can tell curl to skip, say, session4.pdf, when that file does not actually exist? It downloads empty 2KB files instead by default.

P.S. I hope I am posting this at the right place, apologies if it should go to the Apple StackExchange branch. Since it's shell, I though this would be more appropriate.

share|improve this question
    
Tried the -f (--fail) switch? –  manatwork Sep 26 '11 at 10:37
    
By the way, why are you setting the progress bar (-#) while asking for absolutely no output (-s)? –  manatwork Sep 26 '11 at 10:41
    
That worked: I had missed the -f option. And yes, the -# is unnecessary here, it's a leftover from previous tests. Thanks! –  Fr. Sep 26 '11 at 12:10
add comment

1 Answer

Use the -f, --fail option to ask curl to silently skip errors and it will not produce empty files.

In other words, your command should be:

curl -f -s -# "http://URL/session[1-12].pdf" -o "Slides/session#1.pdf";
share|improve this answer
add comment

Your Answer

 
discard

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

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