Ubuntu Bash Script changing file names chronologicaly

Posted by Manifold on Stack Overflow See other posts from Stack Overflow or by Manifold
Published on 2012-12-01T04:30:52Z Indexed on 2012/12/01 5:04 UTC
Read the original article Hit count: 125

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about bash

Related posts about ubuntu