#!/usr/bin/env bash # Walk each immediate subfolder of this directory (e.g. sheep/, zebra/) and # delete every .mp4 file found inside (recursively). set -euo pipefail BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DELETE=0 if [[ "${1:-}" == "--delete" ]]; then DELETE=1 fi find_mp4() { find "$1" -type f -iname '*.mp4' -print0 } for dir in "$BASE"/*/; do [[ -d "$dir" ]] || continue name="$(basename "$dir")" [[ "$name" == ".cache" ]] && continue while IFS= read -r -d '' f; do if [[ "$DELETE" -eq 1 ]]; then rm -f -- "$f" echo "removed $f" else echo "$f" fi done < <(find_mp4 "$dir") done if [[ "$DELETE" -eq 0 ]]; then echo "Dry run only. Run with: $0 --delete" >&2 fi