With zsh:
rm -f /var/log/mbackups/*(.m+6)
same as:
rm -f /var/log/mbackups/*(.^m-7)
Would remove the regular (with .
) files that are not hidden and haven't been modified in the last 7 days. Like for find
's -mtime +7
, m+7
would match on files whose age rounded down to the next integer number of days is strictly greater than 7, so would match on files that are 8 days old or older (a common pitfall when working with find
).
To also remove old hidden files, add the D
glob qualifier.
If there's no matching file, you'll get an error message. You can avoid it by adding the N
glob qualifier (and rm
will then be called without filename argument, but with -f
, it should not complain about it).
-mtime +N
. With GNU find,-mtime +7
will find files that are at least eight days old.find
. It is a POSIX requirement (though IIRC some BSDs are/were not compliant in that regard).