Skip to content

Instantly share code, notes, and snippets.

@deviationist
Created June 2, 2023 22:10
Show Gist options
  • Save deviationist/a6f8b4a8e6c140107759a90938c7d758 to your computer and use it in GitHub Desktop.
Save deviationist/a6f8b4a8e6c140107759a90938c7d758 to your computer and use it in GitHub Desktop.
File counter grouped by file extension, tailored for audio files.
#!/usr/bin/env bash
echo "File type count:"
fileExtensions=( aiff mp3 wav m4a flac alac )
totalFileCount=$(find . -name "*.aiff" -o -name "*.mp3" -o -name "*.wav" -o -name "*.m4a" -o -name "*.flac" -o -name "*.alac" | wc -l)
for fileExtension in "${fileExtensions[@]}"
do
fileCount=$(find . -name "*.${fileExtension}" | wc -l)
percent=`echo "$fileCount * 100 / $totalFileCount" | bc -l`
roundedPercent=`printf "%.0f" $percent`
echo "${fileExtension}: ${fileCount} files (${roundedPercent}%)"
done
echo ""
echo "File extesions found in directory:"
echo $(find . -type f -name '*.*' | sed 's|.*\.||' | sort -u)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment