Friday 31 July 2015

GNU Find does not return results in order

for example, I had: find $CURRENT_BACKUP_DIR -name $1_*.gz | tail -n+8 | xargs -n1 rm to keep the last 7 days backup only.

However, it did not work, as find does not return the results in order.

For me, using sort fixed the problem: find $CURRENT_BACKUP_DIR -name $1_*.gz | sort | tail -n+8 | xargs -n1 rm