把文件復制N份的2個Shell腳本代碼
更新時間:2014年07月10日 09:05:33 投稿:junjie
這篇文章主要介紹了把文件復制N份的2個Shell腳本代碼,一般用在需要大量文件測試時使用,需要的朋友可以參考下
測試時需要大量文件,所以寫了腳本進行拷貝。有規(guī)律的文件名利于引用。
復制代碼 代碼如下:
#!/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
相關文章
Linux下shell腳本監(jiān)控Tomcat的狀態(tài)并實現(xiàn)自動啟動的步驟
這篇文章主要介紹了Linux下shell腳本監(jiān)控Tomcat的狀態(tài)并實現(xiàn)自動啟動的步驟,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友參考下吧2019-12-12
ubuntu修改terminal終端的主機名的實現(xiàn)方法
這篇文章主要介紹了ubuntu修改terminal終端的主機名的實現(xiàn)方法的相關資料,希望通過本文能幫助大家,需要的朋友可以參考下2017-08-08
用expect實現(xiàn)的自動登錄到多臺服務器的shell腳本
自動登錄到多臺服務器的shell腳本,用expect來實現(xiàn)的一段代碼,需要的朋友可以參考下2013-02-02
Linux 分區(qū)初始化為物理卷,把物理卷加入卷組的方法
下面小編就為大家?guī)硪黄狶inux 分區(qū)初始化為物理卷,把物理卷加入卷組的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03

