find_large shell

8 篇文章 0 订阅
#!/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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值