bash exiftool 使用相机型号和日期重命名照片

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28835493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:28:06  来源:igfitidea点击:

exiftool rename photos with camera model and date

bashshellcameraexifexiftool

提问by glasses

I have been sorting my family photos, including some from a recovered backup drive my dad had. many of the photos were named file000268.jpg etc so I looked into renaming utilities, and ended up going with exiftool because I can use it in the shell and write scripts based around it (I use Mac and Ubuntu). I have a simple script working that renames photos to the date taken and it works great, but I am trying to add the camera make/model in front of the date, this will easily help me identify my dad's photos vs. photos from his graphic design clients(I know my parents had a kodak camera).

我一直在整理我的家庭照片,包括一些来自我父亲恢复的备份驱动器。许多照片被命名为 file000268.jpg 等,所以我研究了重命名实用程序,最终使用了 exiftool,因为我可以在 shell 中使用它并基于它编写脚本(我使用 Mac 和 Ubuntu)。我有一个简单的脚本可以将照片重命名为拍摄日期,效果很好,但我正在尝试在日期前添加相机品牌/型号,这将很容易帮助我识别我父亲的照片与他的图片中的照片设计客户(我知道我父母有一台柯达相机)。

Here is the working script to rename photos with the date taken:

这是使用拍摄日期重命名照片的工作脚本:

exiftool '-FileName<DateTimeOriginal' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" /directory/ 

this results in photos named like this:

这导致照片命名如下:

'2002-12-16 14.20.56.jpg'

'2002-12-16 14.20.56.jpg'

I just want to add the camera make/model in front of the year ex:

我只想在年份前面添加相机品牌/型号:

'SONY CYBERSHOT 2002-12-16 14.20.56.jpg'

'索尼 CYBERSHOT 2002-12-16 14.20.56.jpg'

Thanks in advance for any help, I have been doing a ton of googling on this and have been pretty confused.

在此先感谢您的帮助,我一直在为此进行大量的谷歌搜索,但一直很困惑。

回答by speakr

From the exiftool v9.69 manpage:

来自 exiftool v9.69 联机帮助页:

exiftool '-filename<%f_${model;}.%e' dir

Rename all files in "dir" by adding the camera model name to the file name. The semicolon after the tag name inside the braces causes characters which are invalid in Windows file names to be deleted from the tag value (see the -p option documentation for an explanation).

通过将相机型号名称添加到文件名中,重命名“dir”中的所有文件。大括号内标记名称后的分号会导致从标记值中删除 Windows 文件名中无效的字符(有关说明,请参阅 -p 选项文档)。

In your case you can just run exiftoola second time after your initial rename:

在您的情况下,您可以exiftool在初始重命名后再次运行:

exiftool '-filename<${model;} %f.%e' /directory/

Or all in one:

或合二为一:

exiftool '-filename<${model;} ${datetimeoriginal}' -d "%Y-%m-%d %H.%M.%S%%-c.%%e" /directory/