#!/bin/sh
# count how many files of each type are on the device.
# the filenames are saved under each type into "file-type" dir.
if [ $# -ne 1 ]; then
	echo "usage: $0 <dir>"
	echo "counts how many files and of what type are under given dir"
	exit 1
fi
dir=$(realpath $1)
if [ \! -d $dir ]; then
	echo "dir '$dir' doesn't exist!"
	exit 1
fi
rm -rf file-type
mkdir file-type
cd file-type
for file in $(find $dir -type f); do
	base=${file##*/}
	ftype=${base##*.}
	if [ "$ftype" != "$base" ]; then
		echo "$file" >> "$ftype"
	else
		echo "$file" >> no-extension-in-file
	fi
done
for ftype in *; do
	wc -l "$ftype"
done|sort -n

