Skip to content

Instantly share code, notes, and snippets.

@adoyle
Created March 25, 2025 14:52
Show Gist options
  • Save adoyle/5270fd1971e02a5eb120081c3494fd66 to your computer and use it in GitHub Desktop.
Save adoyle/5270fd1971e02a5eb120081c3494fd66 to your computer and use it in GitHub Desktop.
Using the file date, move the file into a directory named YEAR-MON. The directory is created if it doesn't exist.
#/usr/local/bin/bash
DST_DIR=~/Photos/exports
# Organizes files by year/month into the DST_DIR
find . -type f | \
while read i; \
do IFS=' ' read -r -a result <<< $(ls -lUTD %Y-%m "$i");\
mkdir -p $DST_DIR/${result[5]};\
mv "$i" $DST_DIR/${result[5]};\
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment