Skip to content

Using curl to download sequential files

We all know one may use curl to download sequential files like this:

curl -O[01-09].txt

But what if the site admin named the files using a more complicated scheme like “file01_101.txt” and “file02_102.txt”?

You can actually pass a simple for loop using a variable, like this:

for x in {1..9}; do curl -O{$x}_10{$x}.txt; done;

If the URL gets more complicated like “file01-oo.jpg” and “file02-01.jpg” but still have a pattern, you can get creative too!

for x in {1..9}; do y=$(( $x-1 )); 
//for testing// echo "file0$x_$y.jpg"; 
//actual// curl -O{$x}_{$y}.jpg; 

HTH :)

Posted in Apple, English.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.