49 lines
No EOL
959 B
Markdown
49 lines
No EOL
959 B
Markdown
deleting every 10th file
|
|
|
|
```sh
|
|
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Directory containing save files (defaults to current directory)
|
|
DIR="${1:-.}"
|
|
|
|
# Set to 1 to actually delete files; otherwise, preview only
|
|
DELETE=0
|
|
|
|
mapfile -t files < <(
|
|
find "$DIR" -maxdepth 1 -type f \
|
|
-name 'ManualSave_*.sav' \
|
|
-printf '%T@ %p\n' |
|
|
sort -n |
|
|
cut -d' ' -f2-
|
|
)
|
|
|
|
total=${#files[@]}
|
|
|
|
echo "Found $total save files."
|
|
echo "Keeping every 10th file, ordered oldest to newest."
|
|
echo
|
|
|
|
for ((i = 0; i < total; i++)); do
|
|
if (( (i + 1) % 10 == 0 )); then
|
|
echo "KEEP ${files[i]}"
|
|
else
|
|
if (( DELETE )); then
|
|
rm -- "${files[i]}"
|
|
echo "DELETE ${files[i]}"
|
|
else
|
|
echo "WOULD DELETE ${files[i]}"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
echo
|
|
if (( DELETE )); then
|
|
echo "Done."
|
|
else
|
|
echo "Dry run only. No files were deleted."
|
|
echo "To enable deletion, change DELETE=0 to DELETE=1."
|
|
fi
|
|
|
|
``` |