当前位置: 移动技术网 > 网络运营>服务器>Linux > 把文件复制N份的2个Shell脚本代码

把文件复制N份的2个Shell脚本代码

2017年12月12日  | 移动技术网网络运营  | 我要评论

测试时需要大量文件,所以写了脚本进行拷贝。有规律的文件名利于引用。


复制代码 代码如下:

#!/bin/sh
# file name : batchcp.sh
# author: zhouhh
# email: ablozhou@gmail.com
# date : 2008.3.31
 
echo "input your file name"
 
read  filename
 
echo "how many times you want copy?"
 
read times
 
echo "your file name is ${filename}, you want to copy ${times} times."
 
base=`echo ${filename}|cut -d "." -f 1`
ext=`echo ${filename}|cut -d "." -f 2`
 
for(( i=0;i<${times};i++))
do
echo "copy ${base}.${ext} to ${base}$i.${ext} ..."
cp "${base}.${ext}" "${base}$i.${ext}"
done

另一个版本

复制代码 代码如下:

#!/bin/sh
# file name : batchcp.sh
# author: zhouhh
# email: ablozhou@gmail.com
# date : 2008.3.31
 
echo "input your file name"
 
read  filename
 
echo "how many times you want copy?"
 
read times
 
echo "your file name is ${filename}, you want to copy ${times} times."
#find . and cut the left part of the file name using ##
ext=${filename##*.}
#find . and cut the right part of the file name using %
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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网