Set mtime based on date string in filename

旧巷老猫 提交于 2019-12-24 13:26:01

问题


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?


回答1:


$ 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.



来源:https://stackoverflow.com/questions/1066690/set-mtime-based-on-date-string-in-filename

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!