LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   search recursively by exif date? (https://www.linuxquestions.org/questions/programming-9/search-recursively-by-exif-date-790443/)

rioguia 02-20-2010 02:27 PM

search recursively by exif date?
 
I have searched diligently but can't seem to find a way to search by exif date. Most of my searches turned up commands to manipulate EXIF data not just search by it.


I have found some likely tools but suspect that I don't know enough bash to recursively find a .jpg file by it's exif date.

For example, exiprobe and exifgrep look promising (see examples below).

i have made some progress. At first, I couldn't associate the file name with the date given but learned that the "n" option forces each output line to start with the file name.

Now, I need to make the command recurse but can't seem to manage it. Any help would be appreciated.

halloween_IMG_0965.JPG: JPEG.APP1.Ifd0.Exif.DateTimeOriginal = '2009:10:31 20:58:52


If it helps, I have linked to the man pages

http://www.virtual-cafe.com/~dhh/too...ifprobe.1.html
http://www.virtual-cafe.com/~dhh/too...xifgrep.1.html

neonsignal 02-20-2010 05:03 PM

Here is an example using the exif program that comes with libexif to pull out the tags:

Code:

find -name '*.jpg' -exec sh -c '[[ $(exif -t DateTimeOriginal -m "{}") =~ ^2005:01:.. ]]' \; -print
You could apply this same technique to the other EXIF extraction programs too.

The find looks for jpg files. For each file found, it executes a shell which does a test on the exif data. The exif flags are '-t' which selects the DateTimeOriginal tag, and '-m' to show only the tag data. The match is a regular expression (in this case all January 2005 dates). If the exec match succeeds, the find goes on to print the filename.

rioguia 02-20-2010 09:41 PM

not quite working for me
 
Thanks for your quick response.
This looks really close but it appears that my Ubuntu hides the bash some place unexpectedly. I got an error messsage
Quote:

sh: [[: not found
. I searched for possible explanations and most seemed to suggest a permission issue. Assuming this might be a permissions error, I
ran the command under sudo with the same results.

GrapefruiTgirl 02-20-2010 09:52 PM

That error is not telling you that is cannot find bash -- it's saying that "[[" is not found.
I would think (but not certain) that /bin/sh would be linked to /bin/bash on your system, thereby allowing the "[[" test (which is a 'Bashism') to execute without error; but as a test, you might try replacing the "sh" in your `find` command, with "bash" instead, and see if it likes that.
Alternately, you might try replacing the "[[" with "[" but my fear is that you would then need to do some quoting of the items within the [ and ] brackets.

So, in short:

1) try replacing "sh" with "bash".
2) if that fails, replace "[[" with "[" (and of course, replace "]]" with "]" as well) and see what happens there. If you try this, you may then get an error about "too many arguments.." which means you will need to, at the least, put qoutes around the things you are testing.

Sasha

neonsignal 02-20-2010 09:56 PM

I was assuming at least version 3 of bash. What does this report?:
Code:

sh --version

syg00 02-20-2010 10:29 PM

Quote:

Originally Posted by rioguia (Post 3871053)
... but it appears that my Ubuntu hides the bash some place unexpectedly.

This is truer than you imagine. What does this produce
Code:

ls -al $(which sh)
Try using /bin/bash in the solution from neonsignal.

rioguia 02-21-2010 05:49 AM

Thanks that solved it!
 
The /bin/bash suggestions worked.

The output from the which command was as follows;
$ ls -al $(which sh)
lrwxrwxrwx 1 root root 4 2009-06-15 12:30 /bin/sh -> dash

Thanks again!


All times are GMT -5. The time now is 11:49 AM.