#!/bin/bash # Find all .meta files in stage 4 directory mapfile -d '' list < <( find /srv/openslx/nfs/stage4/bwlp/ -type f -name "*.meta" -print0 ) now="$( date +%s )" for file in "${list[@]}"; do # get the atime value from it; this is the last time a client asked for the according image atime="$( grep -oP '(?<=^atime=).*$' "$file" )" diff="$(( (now - atime) / 86400 ))" # check if atime is more than 60 days ago, or continue with next image (( diff > 60 )) || continue # Older than 60 days, fire away file="${file%.meta}" rm -f -- "$file" "$file".* # No space between $file and .* !! done exit 0