#!/bin/bash # Consolidate albums of < 3 tracks to a "medley" album find . -wholename './.git' -prune -o -type d -links 2 \ -exec /bin/bash -c 'a=( "{}"/* ); [[ ${#a[*]} -lt 3 ]]' ';' -print | while IFS=$'\n' read -r dir; do for f in "$dir"/*; do # echo "$f" p1=$(echo "$f" | cut -d/ -f 2) p2=$(basename "$f") if [[ "$p1" == "Various Artists" ]]; then newf="./Various Artists/Medley/$p2" else newf="./Various Artists/Medley/$p1-$p2" fi git mv "$f" "$newf" done done # May need to do multiple times to remove all empty dirs find . -wholename './.git' -prune -o -type d -empty -print | while IFS=$'\n' read -r dir; do echo rmdir "$dir" done