# 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 c) Continue Program - Count each file type from the current directory and below q) Quit at this time to change to the appropriate directory Choice==> \c" read answer case ${answer} in # Runs Program [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} # Lists the directories and performs the commands listed below on each # directory occurrence. for i in $(find . -type d -print) do cd ${current_directory}/${i} 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