Sunday, April 24, 2011

Counting files

I have organized my photos this way: there's a Photos directory, under which there's one subdirectory for each year.  In addition to the JPEG images, these directories also contain files like Picasa.ini.  So, to find out how many pictures I have I can use the find command:
~/d/Photos % find . -type f -iname \*.jpg | wc -l
5101
This command counts the files that have .jpg file extension.  Let's say I want to know the years in which I took more photos, and the years in which I took relatively lesser number of photos.  That can be done using the following command:
% for year in *
do
  echo -n "$year "
  find $year -type f -iname \*.jpg | wc -l
done
2006 98
2007 983
2008 1978
2009 1128
2010 749
2011 165
If you use zsh, you can modify the command to include only the last few years:
% for year in <2009-2011>                   
do
  echo -n "$year "
  find $year -type f -iname \*.jpg | wc -l
done
2009 1128
2010 749
2011 165

No comments:

Post a Comment