Copy the file n copies of 2 shell script code _linux Shell

Source: Internet
Author: User

A large number of files are required for testing, so a script is written to copy. A regular file name facilitates reference.


Copy Code code as follows:

#!/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 do you want copy?"

Read times

echo "Your file name is ${filename} and you are want to copy ${times}."

Base= ' echo ${filename}|cut-d '. "-F 1"
Ext= ' echo ${filename}|cut-d '. "-F 2"

For ((i=0;i<${times};i++))
Todo
echo "Copy ${base}.${ext} to ${base} $i. ${ext} ..."
CP "${base}.${ext}" "${base} $i. ${ext}"
Done

Another version

Copy Code code as follows:

#!/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 do you want copy?"

Read times

echo "Your file name is ${filename} and you are want to copy ${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++))
Todo
echo "Copy ${base}.${ext} to ${base} $i. ${ext} ..."
CP "${base}.${ext}" "${base} $i. ${ext}"
Done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.