Downloading Multiple Files Via Wget (Linux)

A few lines of and the download script is ready

When I first started my website I discussed some of the options of using the command line / terminal to download content from the internet without using a web browser.

Recently I started looking through some of my partially wrote blog posts / ideas for posts and decided to finish / post them. This evenings post is using wget to download multiple sequentially named files via a quick script that can be run via Bash.

geektechstuff_bash_wget_1
A few lines of and the download script is ready

In this example I am using the fantastic Mag Pi magazines PDF directory, which contains PDFs of the Mag Pi magazine – if you like the Raspberry Pi, then you should be reading this magazine.

The PDFs of the magazine are named in the format MagPi??.pdf with the ?? being the issue number. Using a for loop the issues can all be downloaded (to save on bandwidth I’m only downloading issues 50 to 80):

echo “Starting…”

for i in {50..80}

do

  wget https://www.raspberrypi.org/magpi-issues/MagPi$i.pdf

done

geektechstuff_bash_wget_2
wget ‘ing issues of mag pi magazine

The $i represents the value of i which starts at 50 and increases one value at a time to 80. The file can be created in a text editor (e.g. Nano) and then saved with the .sh file extension. Then use the command bash filename.sh to run it, e.g. if you saved it as download.sh use bash download.sh to run the script.

Lots of Mag Pi magazine to read
Lots of Mag Pi magazine to read

And thats it, lots of issues of Mag Pi magazine to enjoy and lots of excellent Raspberry Pi project ideas especially during March’s #MonthOfMaking .

2 thoughts on “Downloading Multiple Files Via Wget (Linux)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.