Thursday, October 25, 2007

[Work] shell programming

Counting files greater than a certain size
#!/bin/sh
# others/countsize
case $# in
0) echo 'Usage: ' $prog ''; exit 1;;
esac

limit=$1
count=0
for f in *
do
if test -f $f
then
size=`ls -s $f| awk '{print $1}'`
if test $size -ge $limit
then
count=$[count+1]
echo $f
fi
fi
done
echo $count "files bigger than " $limit"K"

No comments: