Gangmax Blog

Copy some but not all files

The script says everything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /bin/bash
#
# This script copies all "abconfig*.xml" files and rename them to "abconfig*.template", then copy all the other files without changing their names.
#
# http://stackoverflow.com/questions/1224766/how-do-i-rename-the-extension-of-a-batch-of-files/1225236#1225236
# http://unix.stackexchange.com/questions/41693/how-to-copy-some-but-not-all-files
# http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
# http://www.linuxjournal.com/content/bash-extended-globbing
#

# 1. Copy all XML configuration files.
cp ~/project/conf/abconfig*.xml ~/temp/shell/

cd ~/temp/shell/

for files in abconfig*.xml
do
mv "$files" "${files%.xml}.template"
done

# 2. Copy configuration files other than the XML configuration files.
shopt -s extglob
cp ~/project/conf/!(abconfig*.xml) ~/temp/shell/
shopt -u extglob

Comments