#!/bin/sh
#
# usage: count_types [directory ...]
# counts how many files there are of each type in a specified
# directory (defaults to the current directory).
#
# Uses an associative array to keep track of the # of files per type
# Print out in the format `#_of_files	file_type' for each type of file

find ${*-.} -type f -print | xargs file | awk -F: '
{
        t[$2]++;
}
END {
        for (i in t) printf("%d\t%s\n", t[i],i);

}' | sort -nr	# Sort the result by numeral, in reverse
