Skip to content

Instantly share code, notes, and snippets.

@alexdantas
Created April 24, 2014 22:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdantas/11271729 to your computer and use it in GitHub Desktop.
Save alexdantas/11271729 to your computer and use it in GitHub Desktop.
Downloads all files with a specified extension from a website
#!/usr/bin/bash
#
# wget-all: gets all files from a specified file extension
# on a remote host
function usage() {
echo 'Usage:'
echo ' $ wget-all.sh <remote-host> <filename-extension>'
echo
echo 'Example:'
echo ' $ wget-all.sh alexdantas.net/tmp png'
}
if [[ -z "$@" ]]
then
usage
exit -1
fi
if [[ -z "$2" ]]
then
echo 'No file extension specified'
usage
exit -2
fi
# Thanks, http://stackoverflow.com/a/5045370
CURRENT_DIR="-nH --cut-dirs=1"
wget "$1" -r -l1 --no-parent $CURRENT_DIR -A."$2"
exit 0
@thomhastings
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment