#!/bin/sh # Find file with $findpattern recursively in $findpath # Execute $cmd $file where for all files found # # Usage example: # ./batch_process.sh "/var/www/yohanes/wp-content/uploads" "*.png" "optipng" # ./batch_process.sh "/var/www/yohanes/wp-content/uploads" "*.jpg" "jpegoptim" # # @Author: yohanes.gultom@gmail.com findpath=$1 findpattern=$2 cmd=$3 : ${findpath:="."} find "$findpath" -name "$findpattern" | while read f ; do eval "$cmd $f" done