#!/bin/sh # list files last modified in a given month & year. # License: LGPLv2 # Author: # http://www.pixelbeat.org/ # Changes: # V0.1, 08 Jul 2004, Initial release # V0.2, 04 Oct 2007, Fix reporting for files close to month boundaries # Fix reporting for current month # Support reporting of future dates # Better error checking if test "$Argc" -lt 2 { echo "Usage: $[basename $0] MM YYYY [other find parameters]" >&2 exit 1 } set -e #exit early on error setglobal month = $1 setglobal year = $2 shift; shift if test $month = "12" { setglobal next_year = $[expr $year + 1] setglobal next_year = $[printf "%02d" $next_year] #date requires YY not Y setglobal next_month = '1' } else { setglobal next_year = $year setglobal next_month = $[expr $month + 1] } setglobal now = $[date --utc +%s] setglobal start = $[date --date="$year-$month-01 UTC" +%s] setglobal end = $[date --date="$next_year-$next_month-01 UTC" +%s] if test $start -gt $now { setglobal start = $now setglobal end = ''"" } elif test $end -gt $now { setglobal end = ''"" } setglobal start_days_ago = $[expr '(' $now - $start ')' / 86400] setglobal start_days_ago = $[expr $start_days_ago + 1] if test $end { #faster setglobal end_days_ago = $[expr '(' $now - $end ')' / 86400] find @ARGV -daystart -mtime -$start_days_ago -mtime +$end_days_ago } else { test $[echo -n $month | wc -c] -eq 1 && setglobal month = ""0$month"" test $[echo -n $year | wc -c] -eq 2 && setglobal year = ""20$year"" find @ARGV -daystart -mtime -$start_days_ago -printf "%p\0%Tm-%TY\n" | env LANG=C grep -a "$month-$year$" | cut -d '' -f1 }