简体   繁体   English

在Linux上使用修改后的时间戳批量重命名文件

[英]Batch renaming of files with a modified timestamp on Linux

As part of a personal project I have generated a large number of frames. 作为个人项目的一部分,我生成了大量帧。

I want to rename around 6000 png image files in terminal so that within the name they have the time that the frame represents. 我想在终端中重命名6000个png图像文件,以便在名称中具有框架所代表的时间。

eg 例如

Frame_0001.png to Frame_DDMMYY_HHMMSS.png 从Frame_0001.png到Frame_DDMMYY_HHMMSS.png

Frame_0001.png to Frame_201114_134612.png Frame_0002.png to Frame_201114_134613.png and so on... 从Frame_0001.png到Frame_201114_134612.png从Frame_0002.png到Frame_201114_134613.png等等...

The first frame starts at 13:46:12 on the 20th November 2014. I want the rest of the images to be renamed sequentially so that they are all named after the date and time they represent. 第一帧于2014年11月20日13:46:12开始。我希望其余图像按顺序重命名,以便它们均以其表示的日期和时间命名。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

用perl的(p)重命名:

rename -n "s/\d+/$(date +%d%m%Y_%H%M%S)/" Frame_0001.png

The way I understand your description is that each frame represents one second of a contiguous sequence. 我了解您的描述的方式是,每个帧代表一个连续序列的一秒钟。

start='13:46:12 20 November 2014'
for i in `ls Frame_????.png|sed 's/Frame_\(....\).png/\1/'`
do  time=`date -d "$start - 1 second + $i seconds" +%d%m%y_%H%M%S`
    mv Frame_$i.png Frame_$time.png
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM