# This program will automatically determine every type of file in a file system # aggregate based upon the files' extensions. Additionally, this program will # then count the total number of files per type and generate a report (e.g. tif # files = 1500) in an output file named by the user. Extensions are the part of the filename after the(.)(.tif, .gif, etc). A current directory count or # recursive directory count MENU is presented to the user. THE PROGRAM MUST BE # RUN FROM THE HIGHEST DIRECTORY YOU WANT TO START FROM (e.g. /mss, /mbrs, etc.) # This program creates the variables home and current_directory. pwd | read current_directory cd pwd | read home cd ${current_directory} # This program creates a tmp directory in the home directory of the user if one does not already exist. This program needs to be used in conjunction with # the program home-directory. if test -d ${home}/tmp then print "tmp directory already exists" else mkdir ${home}/tmp fi print "current directory is: ${current_directory}\n" print "PRESS ENTER TO CONTINUE\n\n " read tput clear print "MENU r) Recursive Program - Count each file type in the recursive sub-directories c) Current Directory only - counts only files in current directory q) Quit at this time to change to the appropriate directory Choice==> \c" read answer case ${answer} in # Current directory only [cC]) print "Enter the filename you would like the output to be saved as: \c" read filename #touch ${home}/tmp/${filename} date +"%D" > ${home}/tmp/${filename} #files=$(ls -1) pwd >> ${home}/tmp/${filename} # Lists filetypes by extension and sorts while removing duplicate filetypes ls -1 | cut -d"." -f2 | sort -d -f -u > ${home}/tmp/filetypes # Numbers the filetypes grep -n "^" ${home}/tmp/filetypes > ${home}/tmp/filetypes1 line=1 # Retrieves the number of the last filetype for use in the while statement tail -1 ${home}/tmp/filetypes1 | cut -d":" -f1 | read lastline while test ${line} -le ${lastline} do grep "${line}" ${home}/tmp/filetypes1 | cut -d":" -f2 | read filetype li -lOf *\.${filetype} | wc -l | read filecount print ".${filetype} files = ${filecount}" >> ${home}/tmp/${filename} line=$(expr ${line} + 1) done rm ${home}/tmp/filetypes1 rm ${home}/tmp/filetypes ;; # Runs Program Recursively [rR]) print "Enter the filename you would like the output to be saved as: \c" read filename #touch ${home}/tmp/${filename} print "COUNT of FILE TYPES for $(pwd)\n\t$(date +"%D")" > ${home}/tmp/${filename} # Lists the directories and performs the commands listed below on each # directory occurrence. directories=$(find . -type d -print 2>/dev/null | grep -v "lost+found" | sort) for i in ${directories} do cd /${current_directory}/${i} print "\n$(pwd)" >> ${home}/tmp/${filename} # Lists filetypes by extension and sorts while removing duplicate filetypes li -1Of *\.* | cut -d"." -f2 | sort -d -f -u > ${home}/tmp/filetypes # Numbers the filetypes grep -n "^" ${home}/tmp/filetypes > ${home}/tmp/filetypes1 line=1 # Retrieves the number of the last filetype for use in the while statement tail -1 ${home}/tmp/filetypes1 | cut -d":" -f1 | read lastline while test ${line} -le ${lastline} do grep "${line}" ${home}/tmp/filetypes1 | cut -d":" -f2 | read filetype li -lOf *\.${filetype} | wc -l | read filecount print ".${filetype} files = ${filecount}" >> ${home}/tmp/${filename} line=$(expr ${line} + 1) done print "Your count of filetypes was written to ${home}/tmp/${filename}" done ;; # Quits Program [qQ]) print " Bye " exit ;; # Error Routine *) print "not a valid input" read ;; esac