FilesByWeek

FilesByWeek is a Linux shell (bash) script that lets you check how many files in a directory were created (or last modified) in a certain week of the year, using Linux’s find and date.

It was designed to count the number of emails received in a few Linux/Postfix Maildirs every week (and thus excludes .Sent and any Courier/Dovecot IMAP files), but can be used on any kind of folder.

Download

Usage

./filesbyweek [week] [dir]

Examples:

  • ./filesbyweek 24 — scans the current directory for files created in week 24.
  • ./filesbyweek 24 /var/mail/name@domain.com — scans /var/mail/name@domain.com for files/emails created/received in week 24.

Requirements

  • Linux with bash, date, and find (all available in most distributions).

Notice

  • If the script won’t run, make it executable with the command: chmod +x filesbyweek.sh
  • The date command used in FilesByWeek considers Monday the first day of the week. If you would like Sunday to be the first day of the week, change %W to %U within the date call inside the script.
  • date starts counting weeks on the first Monday (or Sunday) in a new year, which we work around by subtracting 1 from the week count inside the script. However, if the year actually does start on a Monday, you should comment out WEEK=$((WEEK-1)) inside the script.

License

FilesByWeek is released under the MIT license.

Feedback

Feel free to send me feedback or questions regarding FilesByWeek. I’d also like to hear from you if you know how to simply accomplish the same using only find (which should be more efficient).