Tag Archives: UNIX

How to correct photo time using a GPS

A few years back when I got my GPS, I was very happy to be able to geotag my photos. However, I didn’t realize how much my camera time was desynchronising until I noticed that some pictures were not correctly mapped at all because the camera was losing a few minutes every week.

After that, I was setting the camera time when I was going out, except when I forgot, which happened almost every time. And since I became an active member on OpenStreetMap, I started taking pictures of every useful object I could find on my way, I had to find other options to keep my photos up to date in order to map them correctly.

GPS time

I quickly realised that the easiest way would be to take a picture of the time in order to correct it. Based on this photo, I can correct the time of all the photos of my shooting session because it contains an image of the correct time from the GPS and the camera metadata that include the camera time, which is retrievable using exiftool or exiv2 on a UNIX system, or many other tools on Windows and Mac (ViewNX2, GPSPhotoLinker, etc.). Here’s the command line to get the data from exiftool:

exiftool -s -SubSecDateTimeOriginal DSC_9117.JPG 
SubSecDateTimeOriginal : 2013:02:16 21:25:47.80

Based on that, we can see a difference of 41 seconds between the metadata and the GPS time (precision is about more or less one second), where the camera is in advance.

We can now correct the picture time, using exiv2:

exiv2 -a -00:00:41 DSC_9117.JPG 
exiftool -s -SubSecDateTimeOriginal DSC_9117.JPG 
SubSecDateTimeOriginal : 2013:02:16 21:25:06.80

Time is now matching the GPS time, so I can apply the exiv2 command to the other photos.

Note: I use the UTC time zone in both my camera and GPS so I don’t have to worry or set local time on both devices. If the time zones are different, some additional correction may be wanted.

During my last holiday, some people saw me correcting the time of my photos by 8 seconds and really thought I was a nerd because it would make not much difference, but I like it when it’s precise 😉

Enhanced by Zemanta

Elapsed time in UNIX shell

The other day I had enough calculating the time so I just wrote this script:
cat > ~/bin/timediff
if [ -z $2 ]; then
echo "usage: $0 "
echo "ex. $0 11:49 12:51"
exit 1

end=`date +%s -d"$2"`
start=`date +%s -d"$1"`


# Prepend a 0 if minute <10
if [ ${#min} -eq 1 ]; then

echo "$hours:$min"

Of course, it works in some cases only. This one is fine:
$ sh ~/bin/timediff 11:49 12:51

Whereas this one will not work:
$ sh ~/bin/timediff 11:49 1:51

But the output is quite obvious.

Sandro Tosi: Get the lines unique on the first field(s)

uniq is a great tool, since it returns the unique (adjacent) lines of the given input. But it has a limitation: it can’t check for uniqueness only the first N fields (while it allows to ignore them, weird).

So, what to do if you have a long file, and lines with several fields, but you’re only interested in getting the line with the different first 2 field (but all the rest of the line content? awk to the rescue!

$ awk ‘!x[$1]++’ file

will print the (complete) lines of file that has the first field unique. You can set $1$2 to have lines unique on the first 2 fields, and so on. Thanks to this forum post, but there’s some other interesting articles.

Julien Danjou: Using GTK+ stock icons with pynotify

It took me a while to find this, so I’m just blogging it so other people
will be able to find it.

I wanted to send a desktop
pynotify, but using a GTK+ stock

With the following snippet, I managed to do it.

import pynotify
import gtk
n = pynotify.Notification(summary="Summary", message="Message!")
n.set_icon_from_pixbuf(gtk.Label().render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_LARGE_TOOLBAR))

Note that the use of a Label is just to have a widget instanciated to use
the render_icon() method. It could be any widget type as far as I

Axel Beckert: grep everything

During the OpenRheinRuhr I noticed that a friend of mine didn’t know
about zgrep and friends. So I told him what other grep
variations I know and he told me about some grep variations I didn’t
know about.

So here’s our collection of grep wrappers, derivatives and variations.
First I’ll list programs which search for text in different file

grep through what Fixed Strings Wildcards / Basic RegExps Extended RegExps Debian package
uncompressed text files fgrep grep egrep grep
gzip-compressed text files zfgrep zgrep zegrep zutils, gzip
bzip2-compressed text files bzfgrep bzgrep bzegrep bzip2
xz-compressed text files xzfgrep xzgrep xzegrep xz-utils
uncompressed text files in installed Debian packages dfgrep dgrep degrep debian-goodies
gzip-compressed text files in installed Debian packages dzgrep debian-goodies
PDF documents pdfgrep pdfgrep
POD texts podgrep pmtools
E-Mail folder (mbox, MH, Maildir) mboxgrep -G mboxgrep -E mboxgrep
Patches grepdiff grepdiff -E patchutils
Process list pgrep procps
Gnumeric spreadsheets ssgrep -F ssgrep ? gnumeric
Files in ZIP archives zipgrep unzip
ID3 tags in MP3s taggrepper taggrepper
Network packets ngrep ngrep
Tar archives targrep / ptargrep perl (Experimental only for now)

And then there are also greps for special patterns on more or less
normal files:

grep for what uncompressed files compressed files Debian package
PCRE (Perl Compatible Regular Expression) pcregrep (see also the grep -P option) zpcregrep pcregrep
IP Address in a given CIDR range grepcidr grepcidr
XPath expression xml_grep xml-twig-tools

One question is though still unanswered for us: Is there some kind of
meta-grep which chooses per file the right grep from above by looking
at the MIME type of the according files, similar to xdg-open.

Other tools which have grep in their name, but are too special to
properly fit into the above lists:

  • ext3grep: Tool to help recover deleted files on ext3
  • xautomation: Includes a tool named visgrep
    to grep for subimages inside other images.

Includes contributions by Frank Hofmann and Faidon Liambotis.