Set mtime based on date string in filename
问题 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