you can try something like
-------------------------------------------------------------------------
SIZE=$1
echo Listing files Greater than supplied size sorted with the highest first
for i in `ls -Slh | tr -s ' ' | tr ' ' '^' `
do
x=`echo $i| tr '^' '\t' | cut -f5`
y=`echo $x | grep M`
if [ "$y" ]
then
echo $i | tr '^' '\t' | cut -f9
fi
y=`echo $x | grep k`
if [ "$y" ]
then
size=`echo $y | tr 'k' ' ' | tr '.' '\t'| cut -f1`
if test $size -ge $SIZE
then
echo $i | tr '^' '\t' | cut -f9
fi
fi
done
------------------------------------------------------------------------
here just supply the size as commandline argument. This doesnt need any tmp file. Wrote this script in a hurry so for now it will just ignore the decimal part for example 1.2K will be 1 ...just tweak it as per ur need.
lemme knw if this helps
regards
arnab
dipankar das wrote:
Hello Friends
For one of us in GLT (as a part of MCA studies), i made these two scripts. Actually they are one script working in two directions that generate a list of files in a directory bigger or smaller than a particular size you specify.
But, in this script, because sed did not work with variable substitution, i used a very clumsy method of generating a temporary shell command 'comm.sh' that generates the full shell command and gets replaced by the next command.
Can you suggest any better method of doing this?
dipankar das
1. selectfile.big =========
#!/bin/sh [ -f ~/select.list ] && rm ~/select.list echo Generating ascending list of files bigger than given size.; echo -e "What is the lowest size you want? Give in kb:\c"; read givesize ls -sSr1 > ~/list; line=`wc -l ~/list | cut -c1-8`; wline=`expr $line - 1`; tail -"$wline" ~/list > ~/listt; i=1; while [ $i -le $wline ] ; do echo "sed -n '"$i","$i"p'" > ~/comm.sh seline=`cat ~/listt | sh ~/comm.sh`; size=`cat ~/listt | sh ~/comm.sh | cut -c1-5` ; [ $size -ge $givesize ] && echo "$seline">> ~/select.list; i=`expr $i + 1`; done [ -f ~/list ] && rm ~/list; [ -f ~/listt ] && rm ~/listt; [ -f ~/listtt ] && rm ~/listtt; [ -f ~/comm.sh ] && rm ~/comm.sh; cat ~/select.list; echo "Total number of files bigger than $givesize KB is:" wc -l ~/select.list | cut -c1-7 echo "List of selected file is kept in $HOME/select.list"
2. selectfile.small ===========
#!/bin/sh [ -f ~/select.list ] && rm ~/select.list echo Generating ascending list of files smaller than given size.; echo -e "What is the lowest size you want? Give in kb:\c"; read givesize ls -sSr1 > ~/list; line=`wc -l ~/list | cut -c1-8`; wline=`expr $line - 1`; tail -"$wline" ~/list > ~/listt; i=1; while [ $i -le $wline ] ; do echo "sed -n '"$i","$i"p'" > ~/comm.sh seline=`cat ~/listt | sh ~/comm.sh`; size=`cat ~/listt | sh ~/comm.sh | cut -c1-5` ; [ $size -le $givesize ] && echo "$seline">> ~/select.list; i=`expr $i + 1`; done [ -f ~/list ] && rm ~/list; [ -f ~/listt ] && rm ~/listt; [ -f ~/listtt ] && rm ~/listtt; [ -f ~/comm.sh ] && rm ~/comm.sh; cat ~/select.list; echo "Total number of files smaller than $givesize KB is:" wc -l ~/select.list | cut -c1-7 echo "List of selected file is kept in $HOME/select.list"
-- To unsubscribe, send mail to [EMAIL PROTECTED] with the body "unsubscribe ilug-cal" and an empty subject line. FAQ: http://www.ilug-cal.org/node.php?id=3
-- Thanks and Regards, Arnab Ghosh
Alumnus Software Ltd.(www.alumnux.com) INFINITY, Tower II, 2nd Floor Plot - A3, Block - GP, Sector - V Salt Lake City, kolkata - 700091,WB, India phone-+91-033-2357-5626/27/28 extn no. 305.
-- To unsubscribe, send mail to [EMAIL PROTECTED] with the body "unsubscribe ilug-cal" and an empty subject line. FAQ: http://www.ilug-cal.org/node.php?id=3
