40 lines
671 B
Bash
Executable file
40 lines
671 B
Bash
Executable file
#!/bin/sh
|
|
|
|
a=60
|
|
n=
|
|
|
|
help() {
|
|
cat <<EOF
|
|
Usage: `basename "$0"` -h | [-i|-n] [-a AGE] DIR [DIR [...]]
|
|
Findet alle Dateien in DIR/archive, die zu alt sind und loescht sie.
|
|
-a Alter der Datei in Tagen (std: $a)
|
|
-i Fragt vorher nach (siehe rm)
|
|
-n Trockenlauf
|
|
EOF
|
|
exit
|
|
}
|
|
|
|
while getopts hina: o
|
|
do
|
|
case "$o" in
|
|
-) break ;;
|
|
h) help ;;
|
|
a) a="$OPTARG" ; shift ;;
|
|
i) i=-i ;;
|
|
n) n=echo ;;
|
|
*) echo "Unknown Option: $o" >&2
|
|
help
|
|
;;
|
|
esac
|
|
done
|
|
shift `expr $OPTIND - 1`
|
|
|
|
[ 0 -lt $# ] || help
|
|
[ X = X"$a" ] || a="-mtime +$a"
|
|
|
|
for d
|
|
do
|
|
find "$d" -name archive -type d -exec sh -c '
|
|
find "$1" -type f '"$a"' -exec '"$n"' rm '"$i"' -- "{}" \;' -- '{}' \;
|
|
done
|