#!/bin/bash

set -xe
# удаление space-guest-utils образов
COUNT=6
ROOT_DIR="/local_storage/space_agent/"
MASK="space-guest-utils-*.iso"
FILES=""
FILES_CUR=1

QUERY=$( find $ROOT_DIR -maxdepth 1 -type f -name "$MASK" | sort )
if [[ $( echo -e "$QUERY" | wc -l ) -gt $COUNT ]]; then
  echo -e "$QUERY" | head -n -$COUNT | xargs -t rm -rf
#  echo -e "$QUERY" | head -n -$COUNT | xargs -t ls -la
fi
