Skip to content

Instantly share code, notes, and snippets.

@fukata
Created August 22, 2011 14:40
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 fukata/1162526 to your computer and use it in GitHub Desktop.
Save fukata/1162526 to your computer and use it in GitHub Desktop.
move pictures by date
#!/bin/bash
DIR=${1?'pictures directory require.'}
DIR=${DIR%/}
PIC_DIR='YOUR SAVE PICTURE ROOT PATH'
total=$(ls $DIR |wc -l)
count=1
for line in $(ls -lt $DIR |awk '{print $6","$8}')
do
date=$(echo $line|cut -d',' -f1)
name=$(echo $line|cut -d',' -f2)
year=$(echo $date|cut -d'-' -f1)
month=$(echo $date|cut -d'-' -f2)
day=$(echo $date|cut -d'-' -f3)
if [ "$year" = "" -o "$month" = "" -o "$day" = "" ]; then
continue
fi
if [ ! -d "$PIC_DIR/$year" ]; then
mkdir "$PIC_DIR/$year"
fi
if [ ! -d "$PIC_DIR/$year/$month" ]; then
mkdir "$PIC_DIR/$year/$month"
fi
if [ ! -d "$PIC_DIR/$year/$month/$day" ]; then
mkdir "$PIC_DIR/$year/$month/$day"
fi
printf "\r($count/$total) $DIR/$name -> $PIC_DIR/$year/$month/$day/$name"
mv "$DIR/$name" "$PIC_DIR/$year/$month/$day/$name"
count=$(($count + 1))
done
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment