Last active
February 3, 2017 10:18
-
-
Save jollychang/5123118 to your computer and use it in GitHub Desktop.
re-structure folder by date
This file contains 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
if [ ! $1 ]; then | |
echo "Usage: ./pictures.sh jpg" | |
exit 1 | |
fi | |
for f in *."$1"; do | |
FILENAME="$f" | |
YEAR=`date -j -f "%s" $(stat -f "%m" "$FILENAME") +"%Y"` | |
MONTH=`date -j -f "%s" $(stat -f "%m" "$FILENAME") +"%m_%B"` | |
DEST="$YEAR/$MONTH" | |
if [ ! -d "$DEST" ]; then | |
mkdir -p "$DEST" | |
fi | |
echo "Moving $FILENAME to $DEST/$FILENAME ..." | |
mv "$FILENAME" "$DEST/$FILENAME" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment