Created
April 15, 2013 21:37
-
-
Save Korko/5391465 to your computer and use it in GitHub Desktop.
Rename all files in a directory to year_month_day_hour_minutes.ext from date of last modification.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/ksh | |
if [ $# -ne 1 ] ;then | |
echo "USAGE: $0 <directoryToScan>" | |
exit 1; | |
fi | |
for file in "$1"/* ;do | |
extension=${file##*.} | |
fulldate=`ls -al "$file" | tr -s ' ' | cut -d' ' -f6-7` | |
date=${fulldate%% *} | |
fulltime=${fulldate##* } | |
year=${date:0:4} | |
month=${date:5:2} | |
day=${date:8:2} | |
hour=${fulltime:0:2} | |
minutes=${fulltime:3:2} | |
echo "mv \""$file"\" \""$year"_"$month"_"$day"_"$hour"_"$minutes"."$extension"\"" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment