Skip to content

Instantly share code, notes, and snippets.

@PatPeter
Created February 28, 2019 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatPeter/0c25caef3b0dce7390a04bcca31298a3 to your computer and use it in GitHub Desktop.
Save PatPeter/0c25caef3b0dce7390a04bcca31298a3 to your computer and use it in GitHub Desktop.
Applies the Last Modified timestamp in a filename to the file itself
#!/bin/bash
# Finished 2019-01-05 04:41 PM
# https://askubuntu.com/questions/62492/how-can-i-change-the-date-modified-created-of-a-file
# Takes files with date format
# Round 2018-07-10 12.42.38.txt
# And applies this date to the Last Modified date of the file
find ServerLogs/Round* -print | while read filename
do
if [ "$filename" = "ServerLogs" ]
then
continue
fi
echo $filename
round=`echo "$filename" | cut -d'.' -f1`
time=`echo $round | cut -d' ' -f2`
hour=`echo $time | cut -d'-' -f1`
minute=`echo $time | cut -d'-' -f2`
date=`echo $round | cut -d' ' -f3`
day=`echo $date | cut -d'-' -f1`
month=`echo $date | cut -d'-' -f2`
year=`echo $date | cut -d'-' -f3`
# +"%H-%M %d-%m-%Y"
filedate=`date -R -d"$year-$month-$day $hour:$minute"`
if [ $? -ne 0 ]
then
exit
fi
touch -m -d "$filedate" "$filename"
done
find ServerLogs/7*/Round* -print | while read filename
do
echo $filename
round=`basename "$filename"`
round=${round%.*}
#echo "Round: $round"
#round=`echo $filename | cut -d'.' -f1`
date=`echo $round | cut -d' ' -f2`
time=`echo $round | cut -d' ' -f3`
#echo "Date: $date"
#echo "Time: $time"
hour=`echo $time | cut -d'.' -f1`
minute=`echo $time | cut -d'.' -f2`
second=`echo $time | cut -d'.' -f3`
filedate=`date -R -d"$date $hour:$minute:$second"`
echo $filedate
touch -m -d "$filedate" "$filename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment