Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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

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

Your Answer


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.