#!/bin/bash BASE="RecepiesLucas" find "$BASE" -type d | while read -r dir; do # Collect all recipe.json.v* files in the directory files=("$dir"/recipe.json.v*) # Skip if no matching files [ -e "${files[0]}" ] || continue # Filter only files modified on Feb 2 feb2_files=() for f in "${files[@]}"; do # Check modification date (format: YYYY-MM-DD) file_date=$(date -r "$f" +%Y-%m-%d) if [ "$file_date" = "2026-02-02" ]; then feb2_files+=("$f") fi done # Skip if no Feb 2 files [ ${#feb2_files[@]} -gt 0 ] || continue # Sort by timestamp and keep earliest # Sort by numeric suffix at the end of the filename and keep earliest IFS=$'\n' sorted=($(for f in "${feb2_files[@]}"; do # Extract the numeric suffix after .v version="${f##*.v}" # removes everything up to last .v echo "$version $f" done | sort -n | awk '{ $1=""; sub(/^ /,""); print }')) earliest="${sorted[0]}" echo "Keeping $earliest in $dir" mv "$earliest" "$dir/recipe.json" # Delete the rest for f in "${sorted[@]:1}"; do echo "Deleting $f" rm "$f" done done