#! /bin/bash

# ----------------------------------------------------------------
# John Kerl
# kerl.john.r@gmail.com
# 2000/11/01

# A Unix workalike for DOS "del /s".
#
# Examples:
#
#  rmr \*.bak
#  rmr core
#
# which are equivalent to the (longer) commands
#
#   find . -name \*.bak -exec rm -f {} \;
#   find . -name core   -exec rm -f {} \;
#
#
# WARNING:  This is a recursive, non-interactive file remover.
# It can get rid of a lot of files in a hurry, which *might* be what you
# want.
# ----------------------------------------------------------------

set -o noglob

verbose_opt="-v"
if [ "$1" = "-q" ]; then
	verbose_opt=""
fi

if [ $# -lt 1 ]; then
	"Usage: $0 {patterns in single quotes...}" 1>&2
	echo \
	"  Recursively removes files with names matching one or more specified patterns" \
		1>&2
	echo "  Example:  $0 '*.c' '*.h'" 1>&2
	echo "  Example:  $0 '*.[ch]'" 1>&2
	exit
fi

findopts=
for arg
do
	if [ -z "$findopts" ]; then
		findopts="( -name $arg"
	else
		findopts="$findopts -o -name $arg"
	fi
done

if [ "$findopts" != "" ]; then
	findopts="$findopts )"
fi
find . -type f $findopts -exec rm -f $verbose_opt {} \;
