Find Exec Batch Processing

Process files in batches using find with exec and a batch size limit to avoid argument list overflow.

BashCli Tooling

Code

snippet
#!/usr/bin/env bash
set -euo pipefail

DIR="${1:-.}"
BATCH_SIZE=100

find "${DIR}" -type f -name "*.log" -print0 | \
  xargs -0 -n "${BATCH_SIZE}" -- process_batch

process_batch() {
  echo "Processing $# files"
  for f in "$@"; do
    wc -l "$f"
  done
}
export -f process_batch