Ubuntu Bash Script changing file names chronologicaly
- by Manifold
I have this bash script where I am trying to change all *.txt files in a directory to their date of last modification. This is the script:
#!/bin/bash
# Renames the .txt files to the date modified
# FROM: foo.txt Created on: 2012-04-18 18:51:44
# TO: 20120418_185144.txt
for i in *.txt
do
mod_date=$(stat --format %y "$i"|awk '{print $1"_"$2}'|cut -f1 -d'.'|sed 's/[: -]//g')
mv "$i" "$mod_date".txt
done
The error I am getting is:
renamer.sh: 6: renamer.sh: Syntax error: word unexpected (expecting "do")
Any help would be greatly appreciated. Thank you for your time.