修改时间将根据文件名,日期字符串 [英] Set mtime based on date string in filename
本文介绍了修改时间将根据文件名,日期字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于一组文件具有以下命名约定:
datetime_restofname.txt
其中的一个例子是:
200906290700_somewordorphrase.txt
我如何批量更改文件的修改时间以匹配文件名,日期和时间?
解决方案
$为* .TXT F;做触摸-t`回声$ F |切-f1 -d _`$ F; DONE
这会将文件modtime设置下划线之前的日期字符串。
Given a group of files with the following naming convention:
datetime_restofname.txt
an example of which would be:
200906290700_somewordorphrase.txt
how could I batch change the mtime of the files to match the date and time in the filename?
解决方案
$ for f in *.txt; do touch -t `echo $f | cut -f1 -d _` "$f"; done
This will set the file modtime to the date string before the underscore.
这篇关于修改时间将根据文件名,日期字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文