I often import photos and videos (mostly having JPG and MOV extensions) from digital cameras and tablets to my PC, and I would ideally like to see them sorted according to the dates and times they were taken already present in their EXIF data. And hence my wish to rename them all preferably using a simple Nautilus Script by preferably inserting the date and time stamps before each filename.
I have so far managed only to bring together the following Nautilus Script, which I believe is far from perfect:
for i in *.*
do
mv -i "$i" "$(exiftool -CreateDate "$i" | awk -F ': ' '{print $2}')_"$i""
done
What I don't like in this renaming method is the colons used in EXIF date and time stamps (e.g. "2013:09:03 20:55:09_IMG_0108.JPG") which might create problems when transferring these files later to other environments (e.g. Windows).
This command (using exiv2 instead of exiftool) conveniently enables manipulation of date and time stamps but its drawback is that it doesn't work on video (e.g. MOV) files:
exiv2 -k -r '%Y-%m-%d_%H-%M-%S_:basename:' rename "$i"
So I'm hoping someone can come up with a better solution. And it would be magic if it even managed to convert the original filenames and extensions to lowercase as well!
I needed to rename my photos and found this question here -- I just found out that
exiftool
handles it natively:From http://www.sno.phy.queensu.ca/~phil/exiftool/filename.html
If you want to keep track of original filename and write extension lower case:
The same works also with the whole filename in lowercase:
You could run the naming scheme through
sed
, to replace the colons with dashes and spaces with underscores, like so:As for making the whole thing lowercase, you could use
rename
:Or you could do it within your script using
sed
, as in:...and then use the
$j
variable in place of the final$i
of yourmv
line. This sed way is slightly more portable (if that matters to you) as different linux distros have different rename commands, while sed is universal.Or, alternatively, the script can be modified as follows to perform filename conversion to lowercase at the beginning using
tr
instead:To perform slightly different commands for different file types, a bash case statement can be used in this script. For example:
In this example, renaming of MOV files that have CreateDate timestamps ANY NUMBER of hours AFTER OR BEFORE JPG files is adjusted by using another (-tur) EXIF data and removing that that time difference suffix, and it might be necessary to change -tur part according to the location set in the system.
I'd use
krename
for this. ItI know you said that you preferred a script, however, if you are open to a free Java application you can use AmoK Exif Sorter
pyRenamer will not work on my new installed Ubuntu 16.04, therefore I have to find another way to solve this problem too.
I have files such as
IMG_0001.JPG
,IMG_0002.JPG
,... in one folder.I found this question on Stack Overflow useful.
Install "exiv2" first. I used it as follows:
The output filenames are
YYYYMMDD_HHMMSS_0001.JPG
,YYYYMMDD_HHMMSS_0002.JPG
,... etc. Even where the photos were taken at the same second, the original photo serial number will make the difference.