Wednesday, 2 July 2014

Managing Your Pictures with exiftool

Hey guys, hope you all are enjoying Linux. Do you know the best thing I like about Linux? It gives you a very powerful command line, in which by typing only a few commands, you can control your machine. Today we will discuss about a command line tool, called the exiftool,written in Perl.

Exif stands for Exchangeable image file format ( we will not write it as EXIF, but exif ) is the general image format of the digital cameras and other image capturing devices. Apart from the file format, it consists of certain tags which form the metadata of any image file.

All picture management software use these exif tags to manage and sort pictures. The exiftool command utility helps you to mange your pictures and their tags. Just imagine, instead of opening your software, and sorting pictures there, you simply open the command line, type in a one line command, and your work is done!

The major difference between using command line and any equivalent GUI software is that the former is much more faster and powerful, and needs minimum system resources.

Firstly, make sure that you have exiftool installed. If not, you can install it in Ubuntu ( and its variations) by:

sudo apt-get install libimage-exiftool-perl

In general, open your package manager, and search for “exiftool”. You can then install that package.

For any further help, please visit the links below:

Now, we are assuming that we have a “pictures” folder, containing large number of pictures.
Well, this is the general case when we, in a hurry, just keep on dumping in the pictures captured from our digital camera into one folder, and later spend hours in sorting them out.

Before proceeding, let me tell you that actions done from the command line are undo-able, hence make sure you back up your folder, in case you want to revert back.

We want to sort these pictures according to the date and time of pictures taken,i.e., the entire picture directory will contain subdirectories bearing the year name of its contents. Then each such subdirectory will contain further subdirectories bearing the month name of the pictures.

For example, say our picture was taken on “21 st August, 2013” then that picture will be contained in pictures/2013/August/

Firstly, navigate to the parent directory of “pictures”. Now type in the following command and hit enter. Viola! Your work is done!

exiftool '-Directory<CreateDate' -d ./pictures/%Y/%m-%B -r ./pictures/

Let us try to understand this command. As we know, all Linux commands follow the order

<command name> <options> <file/directory arguments>

Here also,

exiftool :

the command name

'Directory<CreateDate' :

tells exiftool to make directories according to the “CreateDate” tag of the pictures

-d :

'd' option is for the date-format string, which defines the structure of our directories to be made.
  • %Y means full year notation, e.g. 2012, 1993, etc.
  • %m means month number, e.g, 01 for January
  • %B is for full month name, e.g. January, March, December, etc.

Thus our directory structure for a picture taken on 31/01/14 will be “2014/01-January/”.

Notice I have given the month number along with the month name so that the folders remain sorted when we will view them in any file manager.

If you want the list of all available date formats used in Linux, type in

man date

-r :

'r' option stands for recursive operation,i.e., our command will look for all pictures in all subdirectories in the “pictures” directory.

./pictures/ :

It is the address of the source directory to work on.

If we want to simply copy our pictures to another directory, instead of moving them, we can use the '-o .' option. I will strongly recommend this, so that you always have a backup. Our command will be:

exiftool -o . '-Directory<CreateDate' -d ./newtry/%Y/%m-%B -r ./pictures/

This will copy the contents of the “pictures” directory to “newtry” directory and sort them there accordingly, leaving your “pictures” directory untouched.

Now let us go to our "pictures", to see its contents:

As you can see, now my folder is well sorted. Thus, the powerful exiftool allows us to manage our pictures very easily. For more information type this in your terminal;

man exiftool

This will show you the manual page for exiftool.

If you have any questions or suggestions, feel free to write below in the comment box.

No comments:

Post a Comment