linuxでファイル転送を実現するshスクリプト
実装目標:CNディレクトリの下にいくつかのフォルダがあり、各フォルダにはCNで始まる一連のサブフォルダがあり、ここでCNで始まるこれらのサブフォルダ実装をフォルダ名で整理して保存する必要がある.例えば、/home/CN/temp/CN 2008,147,8023のフォルダを/home/CN/2008/1478/CN 2008,147,8023に保存すると、shellコマンドは以下の通りである.
#!/bin/bash
# for
count=1
for file in ../CN/*
do
if [ -d ../CN/${file} ]
then
for file1 in ${file}/CN*
do
if [ -d ${file1} ]
then
string=${file1:11}
a=${string:0:2}
b=${string:2:4}
c=${string:6:4}
echo ${a} and ${b} and ${c}
if [ ! -d ../CN/${b} ]
then mkdir ../CN/${b}
fi
if [ ! -d ../CN/${b}/${c} ]
then mkdir ../CN/${b}/${c}
fi
if [ ! -d ../CN/${b}/${c}/${string} ]
then
cp -R ${file1} ../CN/${b}/${c}/${string}
echo sucessfully copyed
count=$[ $count + 1 ]
echo ${count} has been copyed
fi
fi
done
fi
done >output.txt