shell 指定目录 指定文件个数、大小 创建多个文件

#!/bin/sh
#author: peter
#create time:2012-05-18
#Create some bigfile for zecloud Performance test
#Execution: sh creat_bigfile.sh  < -d dirname > | < -n filenum >  [ -h|--help]


#help
function Usage {
clear
echo ""
echo "USAGE: sh creat_bigfile.sh  < -d dirname > | < -n filenum >  | <-s filesize>[ -h|--help]"
echo ""
}


TEMP_OPT=`getopt -o d:n:s: -n 'creat_bigfile.sh' -- "$@"`


if [ $? != 0 -o $# == 0 ] ; then
    Usage
exit 1
fi


eval set -- "$TEMP_OPT"


while true; do
case "$1" in
-d) dirname=$2;  shift 2;;
-n) filenum=$2; shift 2;;
-s) filesize=$2; shift 2;;
--) shift; break;;
*)  Usage;exit 1
esac
done


mkdir -p dirname
cd dirname
for ((i=0;i<$filenum;i++)); do
dd if=/dev/zero of=fd$i bs=1M count=$filesize;
done

你可能感兴趣的:(SHELL)