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.
Best Answer
You should decompose your goal into several steps easier to solve. This will have two advantages:
The scripts below basically follows these steps:
/path/to/foo.mp3
which is 3000000 large, it will append3000000 /path/to/foo.mp3
at the end of a temporary file namedmp3
.m4a
and create the two other filesm4a_aac
andm4a_alac
based on the test you gave in the question.Here is the script: