把文件复制N份的2个Shell脚本代码
测试时需要大量文件,所以写了脚本进行拷贝。有规律的文件名利于引用。
#!/bin/sh #filename:batchcp.sh #author:zhouhh #Email:ablozhou@gmail.com #Date:2008.3.31 echo"inputyourfilename" read FILENAME echo"howmanytimesyouwantcopy?" readTIMES echo"yourfilenameis${FILENAME},youwanttocopy${TIMES}times." BASE=`echo${FILENAME}|cut-d"."-f1` EXT=`echo${FILENAME}|cut-d"."-f2` for((i=0;i<${TIMES};i++)) do echo"copy${BASE}.${EXT}to${BASE}$i.${EXT}..." cp"${BASE}.${EXT}""${BASE}$i.${EXT}" done
另一个版本
#!/bin/sh #filename:batchcp.sh #author:zhouhh #Email:ablozhou@gmail.com #Date:2008.3.31 echo"inputyourfilename" read FILENAME echo"howmanytimesyouwantcopy?" readTIMES echo"yourfilenameis${FILENAME},youwanttocopy${TIMES}times." #find.andcuttheleftpartofthefilenameusing## EXT=${FILENAME##*.} #find.andcuttherightpartofthefilenameusing% BASE=${FILENAME%.*} echo"base:$BASE" echo"ext:$EXT" for((i=0;i<${TIMES};i++)) do echo"copy${BASE}.${EXT}to${BASE}$i.${EXT}..." cp"${BASE}.${EXT}""${BASE}$i.${EXT}" done