Friday, March 18, 2011

Finding count of files according to modification month yearwise

To find count of files in a folder according to their month,i write down a script(i.e. not so awesome script but that do my task easily).

For ex- A folder abcd has 80000 and you know you created files in that folder at 2009 and current year is 2011 then finding count of files according to their month is so easy.

#!/bin/bash
loc=”/home/abcd” #—-This is a location this can be any location
year=”2009|2010|2011″
mon=”Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec”

for((i=1;i<=3;i++))
do
for((j=1;j<=12;j++))
do
year1=$(echo $year|cut -d”|” -f$i)
mon1=$(echo $mon|cut -d”|” -f$j)
echo “$mon1-$year1: $(ls -al –time-style=+%b-%Y $loc|grep “$mon1-$year1″|wc -l)”
done

done


And output like

Jan-2009:200

Feb-2009:488

and so on…

No comments: