Created
February 24, 2026 20:03
-
-
Save kousu/e1ad295d711749d5b355c007101fd177 to your computer and use it in GitHub Desktop.
sort DCIM (camera) files by date
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/bash | |
| # | |
| # Sort Camera folders (e.g. "/mnt/DCIM/Camera") into monthly folders in the _current directory_ | |
| # | |
| # install to your ~/.local/bin or somewhere else on your $PATH | |
| # copy everything off your phone to a staging folder or two | |
| # usage: | |
| # cd $PATH_TO_ARCHIVE | |
| # sort-dcim.sh $STAGING_FOLDER_1 $ | |
| # | |
| # bug: the year range is hard-coded :shrug: | |
| # | |
| # WTFPL 2024 kousu <nick@kousu.ca> | |
| set -eu | |
| TARGET=. | |
| if [ "$#" -le 0 ]; then | |
| exit 0 | |
| fi | |
| for source_folder in "${@}"; do | |
| echo "$source_folder" | |
| # TODO: detect available years from the files themselves? | |
| for YEAR in `seq 2020 2030`; do | |
| for MONTH in `seq 1 12`; do | |
| MONTH="$(printf '%02d' "$MONTH")" | |
| if find "$source_folder" -maxdepth 1 -type f -name "*_${YEAR}${MONTH}*_*.*" 2>/dev/null | grep -q . ; then | |
| mkdir -vp "$TARGET/${YEAR}/$MONTH" | |
| time mv -vn "$source_folder"/*_${YEAR}${MONTH}*_*.* "$TARGET/${YEAR}/$MONTH" | |
| time (set -x; sync) | |
| fi | |
| done | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment