Get Updates by Email

Friday, 21 September 2012

Doing Things to Groups of Files

After the last piece on sorting out the files into sub-directories according to their image dimensions, I decided that it would be smart to delete files that obviously weren't my target. Meaning to say that, if we are looking for files of dimension 640x480 or 480x640, all those sub-directories with lesser resolution should be deleted. So, I got rid of all the files and sub-directories with one side that's less than 200px.
rm ??x???/*.*
rmdir ??x???

This helped get rid of sub-directories with names like 99x480.

Adding a "1" helped me get rid of sub-directories from 100x??? to 199x???.
rm 1??x???/*.*
rmdir 1??x???
Obviously, a good thing need to be used again in another way. So another 4 commands helped zap off the portraits after we got rid of the landscapes.
rm ???x??/*.*
rmdir ???x??
rm ???x1??/*.*
rmdir ???x1??

But after that, I wanted to deal with files that had 200 or more pixels on one side. So I did some research and came up with this:
for i in `ls 2??x???/*.* | grep jpg`; do if [ -f $i ]; then gthumb $i; fi; done

The command lists all the directories that correspond to "2??x???". If a JPG file is found, it is checked whether it exists. If it does, it is sent to "GThumb". This is because while opening GThumb for file #1, I may delete file #2, #3 and #4. The if-fi pair helps prevent sending invalid arguments to GThumb. Through this means, I can cycle through the files in the search result.

While using GThumb, I tend to use the following key-combinations.
Del = Move to Trash
Ctrl-Q  = Quit

Thanks  to the following two websites for providing the solution.
  1. StackOverflow, How do I send multiple from one command to another in bash?
  2.  ElectricToolBox, Test if a file exists with BASH Shell