1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Reference: https://unix.stackexchange.com/a/466596

# dir="/path/to/directory"
# cd "$dir"

for x in *; do
    if [ -f "$x" ]; then
        d=$(date -r "$x" +%Y/%m)
        mkdir -pv "$d"
        mv -v -- "$x" "$d/"
    fi
done