#!/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 global month := $1 global year := $2 shift; shift if test $month = "12" { global next_year := $[expr $year + 1] global next_year := $[printf "%02d" $next_year] #date requires YY not Y global next_month := '1' } else { global next_year := $year global next_month := $[expr $month + 1] } global now := $[date --utc +%s] global start := $[date --date="$year-$month-01 UTC" +%s] global end := $[date --date="$next_year-$next_month-01 UTC" +%s] if test $start -gt $now { global start := $now global end := ''"" } elif test $end -gt $now { global end := ''"" } global start_days_ago := $[expr '(' $now - $start ')' / 86400] global start_days_ago := $[expr $start_days_ago + 1] if test $end { #faster global 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 && global month := ""0$month"" test $[echo -n $year | wc -c] -eq 2 && global 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 } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(-lt)} {(2)} {(Lit_Other "]")}) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("Usage: ") (CommandSubPart command_list: (CommandList children:[(C {(basename)} {($ VSub_Number "$0")})]) left_token: spids: [58 62] ) (" MM YYYY [other find parameters]") ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[66])] ) (C {(exit)} {(1)}) ] spids: [-1 51] ) ] spids: [-1 74] ) (C {(set)} {(-e)}) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:month) op:Equal rhs:{($ VSub_Number "$1")} spids:[85])] spids: [85] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:year) op:Equal rhs:{($ VSub_Number "$2")} spids:[88])] spids: [88] ) (Sentence child:(C {(shift)}) terminator:) (C {(shift)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$month"))} {(Lit_Other "=")} {(DQ (12))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:next_year) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Name "$year")} {(Lit_Other "+")} {(1)})] ) left_token: spids: [118 126] ) } spids: [117] ) ] spids: [117] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:next_year) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(printf)} {(DQ ("%02d"))} {($ VSub_Name "$next_year")})] ) left_token: spids: [130 138] ) } spids: [129] ) ] spids: [129] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:next_month) op:Equal rhs:{(1)} spids:[144])] spids: [144] ) ] spids: [-1 114] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:next_year) op: Equal rhs: {($ VSub_Name "$year")} spids: [150] ) ] spids: [150] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:next_month) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Name "$month")} {(Lit_Other "+")} {(1)})] ) left_token: spids: [155 163] ) } spids: [154] ) ] spids: [154] ) ] spids: [147 165] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:now) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(date)} {(--utc)} {(Lit_Other "+") (Lit_Other "%") (s)})] ) left_token: spids: [168 176] ) } spids: [167] ) ] spids: [167] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:start) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(date)} {(--date) (Lit_Other "=") (DQ ($ VSub_Name "$year") (-) ($ VSub_Name "$month") ("-01 UTC")) } {(Lit_Other "+") (Lit_Other "%") (s)} ) ] ) left_token: spids: [179 194] ) } spids: [178] ) ] spids: [178] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:end) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(date)} {(--date) (Lit_Other "=") (DQ ($ VSub_Name "$next_year") (-) ($ VSub_Name "$next_month") ("-01 UTC")) } {(Lit_Other "+") (Lit_Other "%") (s)} ) ] ) left_token: spids: [197 212] ) } spids: [196] ) ] spids: [196] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$start")} {(-gt)} {($ VSub_Name "$now")} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:start) op: Equal rhs: {($ VSub_Name "$now")} spids: [231] ) ] spids: [231] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:end) op:Equal rhs:{(DQ )} spids:[235])] spids: [235] ) ] spids: [-1 228] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {($ VSub_Name "$end")} {(-gt)} {($ VSub_Name "$now")} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:end) op:Equal rhs:{(DQ )} spids:[255])] spids: [255] ) ] spids: [239 252] ) ] spids: [-1 259] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:start_days_ago) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(EscapedLiteralPart token:)} {($ VSub_Name "$now")} {(-)} {($ VSub_Name "$start")} {(EscapedLiteralPart token:)} {(/)} {(86400)} ) ] ) left_token: spids: [263 279] ) } spids: [262] ) ] spids: [262] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:start_days_ago) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(expr)} {($ VSub_Name "$start_days_ago")} {(Lit_Other "+")} {(1)})] ) left_token: spids: [282 290] ) } spids: [281] ) ] spids: [281] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$end"))} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:end_days_ago) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(EscapedLiteralPart token:)} {($ VSub_Name "$now")} {(-)} {($ VSub_Name "$end")} {(EscapedLiteralPart token:)} {(/)} {(86400)} ) ] ) left_token: spids: [310 326] ) } spids: [309] ) ] spids: [309] ) (C {(find)} {(DQ ($ VSub_At "$@"))} {(-daystart)} {(-mtime)} {(-) ($ VSub_Name "$start_days_ago")} {(-mtime)} {(Lit_Other "+") ($ VSub_Name "$end_days_ago")} ) ] spids: [-1 303] ) ] else_action: [ (AndOr children: [ (C {(Lit_Other "[")} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(echo)} {(-n)} {($ VSub_Name "$month")}) (C {(wc)} {(-c)})] negated: False ) ] ) left_token: spids: [352 364] ) } {(-eq)} {(1)} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:month) op: Equal rhs: {(DQ (0) ($ VSub_Name "$month"))} spids: [374] ) ] spids: [374] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(echo)} {(-n)} {($ VSub_Name "$year")}) (C {(wc)} {(-c)})] negated: False ) ] ) left_token: spids: [383 395] ) } {(-eq)} {(2)} {(Lit_Other "]")} ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:year) op: Equal rhs: {(DQ (20) ($ VSub_Name "$year"))} spids: [405] ) ] spids: [405] ) ] op_id: Op_DAmp ) (Pipeline children: [ (C {(find)} {(DQ ($ VSub_At "$@"))} {(-daystart)} {(-mtime)} {(-) ($ VSub_Name "$start_days_ago")} {(-printf)} { (DQ ("%p") (EscapedLiteralPart token:) ("%Tm-%TY") (EscapedLiteralPart token:) ) } ) (SimpleCommand words: [ {(grep)} {(-a)} {(DQ ($ VSub_Name "$month") (-) ($ VSub_Name "$year") (Lit_Other "$"))} ] more_env: [(env_pair name:LANG val:{(C)} spids:[437])] ) (C {(cut)} {(-d)} {(SQ )} {(-f1)}) ] negated: False ) ] spids: [347 463] ) ] )