May 2017
Beginner
552 pages
28h 47m
English
To enumerate file type statistics, follow these steps:
$ file filename
$ file /etc/passwd
/etc/passwd: ASCII text
$ file -b filename
ASCII text
#!/bin/bash
# Filename: filestat.sh
if [ $# -ne 1 ];
then
echo "Usage is $0 basepath";
exit
fi
path=$1
declare -A statarray;
while read line;
do
ftype=`file -b "$line" | cut -d, -f1`
let statarray["$ftype"]++;
done < (find $path -type f -print)
echo ============ File types and counts =============
for ftype in "${!statarray[@]}";
do
echo $ftype : ${statarray["$ftype"]}
done
The usage is as follows:
$ ./filestat.sh /home/slynux/temp ...