Download apt-get Packages in Parallel with this Shell Script

Sometimes you want to apt-get installer packages in Debian or Ubuntu Linux, but downloading a lot of them in series can take a really long time. Here’s a script that does it for you; all you do is tell it what packages, and it fetches all the dependencies.

A full listing is below.

My thanks to John M. for the inspiration for this script.

# usage function to display help for the hapless user
usage ()
mycmd=`basename $0`
echo "$mycmd"
echo "usage: $mycmd package [p2 [p3 [...]]]"
echo "Downloads apt packages in parallel"
# test if we have an arguments on the command line
if [ $# -lt 1 ]
# go to cache dir
cd /var/cache/apt/archives
# get list of debs
apt-get install -qq --print-uris $@ > /tmp/debs.list
# download them
egrep -o -e "http://[^']+" /tmp/debs.list | xargs -i{} -l3 -P5 wget -nv