I'm putting a script together to sort a very large music collection. It's approx 22000 albums, a mixture of FLAC, WAV, AIFF, M4A (AAC & ALAC).
So far, I can sort by file type and get a total size of each type.
ftypes=$(find . -type f | grep -iE ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort -f | uniq -i)
for ft in $ftypes
do
echo -n "$ft "
find . -name "*${ft}" -print0 | xargs -0 du -hc | grep total | awk '{print $1}'
done
I'd like to edit this to get the number of files by file type as well as the total size.
Now, the M4A files could be either AAC or ALAC, and I'd like to know how many of each.
I can find and print a list of ALAC files with
find . -name \*.m4a | while read file; do avprobe "$file" 2>&1 | grep -q 'Audio: alac' && echo "$file"; done
but I'm lost on how to get the total file count and size, instead of a list of file names, and combine it all into one script.
Basically, I'd like to output:
- List of file types
- Number of files by filetype
- Total size by filetype
- M4A total number of AAC & total size
- M4A total number of ALAC & total size
Depending on how well this works, I may consider using this to sort files into directories based on the output.