#!/bin/ksh
function usage
{
echo "\n***************************************"
echo "\n\nUSAGE: findlarge.ksh [Number_Of_Meg_Bytes]"
echo "\nEXAMPLE: filelarge.ksh 5"
echo "\n\nWill Find Files Larger Than 5 Mb in, and Below, the Current Directory..."
echo "\n\nEXITING...\n"
echo "\n***************************************"
exit
}
############################################
function cleanup
{
echo "\n********************************************************"
echo "\n\nEXITING ON A TRAPPED SIGNAL..."
echo "\n\n********************************************************\n"
exit
}
############################################
# Set a trap to exit. REMEMBER - CANNOT TRAP ON kill -9 !!!!
trap 'cleanup' 1 2 3 15
############################################
# Check for the correct number of arguments and a number
# Greater than zero
if [ $# -ne 1 ]
then
usage
fi
if [ $1 -lt 1 ]
then
usage
fi
############################################
# Define and initialize files and variables here...
THISHOST=`hostname` # Hostname of this machine
DATESTAMP=`date +"%h%d:%Y:%T"`
SEARCH_PATH=`pwd` # Top level directory to search
MEG_BYTES=$1 # Number of Mb for file size trigger
DATAFILE="/tmp/filesize_datafile.out" # Data storage file
>$DATAFILE # Initialize to a null file
OUTFILE="/tmp/largefiles.out" # Output user file
>$OUTFILE # Initialize to a null file
HOLDFILE="/tmp/temp_hold_file.out" # Temporary storage file
>$HOLDFILE # Initialize to a null file
############################################
# Prepare the output user file
echo "\n\nSearching for Files Larger Than ${MEG_BYTES}Mb starting in:"
echo "\n==> $SEARCH_PATH"
echo "\n\nPlease Standby for the Search Results..."
echo "\n\nLarge Files Search Results:" >> $OUTFILE
echo "\nHostname of Machine: $THISHOST" >> $OUTFILE
echo "\nTop Level Directory of Search:" >> $OUTFILE
echo "\n==> $SEARCH_PATH" >> $OUTFILE
echo "\nDate/Time of Search: `date`" >> $OUTFILE
echo "\n\nSearch Results Sorted by Time:" >> $OUTFILE
############################################
# Search for files > $MEG_BYTES starting at the $SEARCH_PATH
find $SEARCH_PATH -type f -size +${MEG_BYTES}000000c \
-print > $HOLDFILE
# How many files were found?
if [ -s $HOLDFILE ]
then
NUMBER_OF_FILES=`cat $HOLDFILE | wc -l`
echo "\n\nNumber of Files Found: ==> $NUMBER_OF_FILES\n\n" >> $OUTFILE
# Append to the end of the Output File...
ls -lt `cat $HOLDFILE` >> $OUTFILE
# Display the Time Sorted Output File...
more $OUTFILE
echo "\n\nThese Search Results are Stored in ==> $OUTFILE"
echo "\n\nSearch Complete...EXITING...\n\n\n"
else
cat $OUTFILE # Show the header information
echo "\n\nNo Files were Found in the Search Path that"
echo "are Larger than ${MEG_BYTES}Mb\n\n"
echo "\nEXITING...\n\n"
fi
[root@vzwc1 oracle]# ./find_large.sh 200
\n\nSearching for Files Larger Than 200Mb starting in:
\n==> /home/oracle
\n\nPlease Standby for the Search Results...
\n\nLarge Files Search Results:
\nHostname of Machine: vzwc1
\nTop Level Directory of Search:
\n==> /home/oracle
\nDate/Time of Search: Thu Oct 17 23:24:53 CST 2013
\n\nSearch Results Sorted by Time:
\n\nNumber of Files Found: ==> 1\n\n
-rw-rw-r-- 1 oracle oinstall 227624960 Jul 19 01:49 /home/oracle/fbo_ggs_Linux_x64_ora11g_64bit.tar
\n\nThese Search Results are Stored in ==> /tmp/largefiles.out
\n\nSearch Complete...EXITING...\n\n\n