#!/bin/bash
# Set the base directory containing the files
SOURCE_DIR="/path/to/your/files" # Change this to your directory
# Change to the source directory
cd "$SOURCE_DIR" || exit 1
# Loop over all files (images, videos, etc.) in the source directory
for file in *; do
# Make sure it's a file (not a directory)
if [ -f "$file" ]; then
# Get the creation month and year (format: YYYY-MM)
month_year=$(stat --format='%y' "$file" | cut -d ' ' -f 1 | cut -d '-' -f 1,2)
# Create a directory for the month/year if it doesn't exist
mkdir -p "$month_year"
# Move the file into the corresponding directory
mv "$file" "$month_year/"
fi
done