标签: bash timestamp filenames
给定一组具有以下命名约定的文件:
datetime_restofname.txt
其中一个例子是:
200906290700_somewordorphrase.txt
如何批量更改文件的mtime以匹配文件名中的日期和时间?
答案 0 :(得分:7)
$ for f in *.txt; do touch -t `echo $f | cut -f1 -d _` "$f"; done
这会将文件modtime设置为下划线之前的日期字符串。