#!/bin/bash
set -e -u -C
cd /path/to/files/
# store list of files in a shell variable
# NO SPACES, NO TABS, NO NEWLINES, NO BACKSLASHES, ETC
FLIST=$(ls -1)
# format the upper limit on deletion as number of seconds since the Epoch
LIMIT=$(date -d 'now - 1 day' +%s)
# get a list of timestamps in "month day year hour:minute" format from FLIST
# convert them to seconds since the epoch
# paste them with the original list of files
# select files below the limit
# remove selected files
sed -r 's/^.*([0-9]{4})-([a-zA-Z]{3})-([0-9]{2})_([0-9]{2})-([0-9]{2}).*$/\2 \3 \1 \4:\5/' <<<"$FLIST" \
| date -f - +%s \
| paste - <(printf '%s\n' "$FLIST") \
| while read STAMP FNAME; do
if [ "$STAMP" -lt "$LIMIT" ]; then
# printf is also a bash builtin
printf '%s\n' "$FNAME"
fi
done \
| xargs rm --