You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用ExifTool直接替换JPG元数据FileModifyDate中的年份?

问题:用ExifTool直接替换JPG文件修改日期中的年份

我在Linux Bash环境中用以下脚本手动修改JPG元数据的文件修改日期,脚本可以正常运行:

date_field=`exiftool -FileModifyDate file.jpg`
raw_date=${date_field:34:19}
new_date=${raw_date/2024/2022}
exiftool -overwrite_original "-FileModifyDate=$new_date" file.jpg

但我想直接用ExifTool完成这个操作,尝试了以下命令却未生效,也没有报错:

exiftool -overwrite_original '-FileModifyDate<${FileModifyDate/2024/2022}' file.jpg

请问如何编写正确的替换命令?


解决方法

你之前的命令无效是因为误用了Bash的变量替换语法,ExifTool有自己的内置字符串替换规则,正确的写法需要使用ExifTool的表达式语法:

exiftool -overwrite_original '-FileModifyDate<${FileModifyDate;s/2024/2022/}' file.jpg

说明:

  • s/2024/2022/是ExifTool内置的替换语法,用于将日期中的2024替换为2022
  • <符号表示从原FileModifyDate标签取值,修改后再赋值回该标签
  • 单引号包裹整个参数,避免Bash解析其中的特殊字符和变量,确保替换逻辑由ExifTool处理

执行完命令后,你可以用exiftool -FileModifyDate file.jpg验证修改是否成功。

内容的提问来源于stack exchange,提问作者e_moro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 07:02:06