读书人

linux上实现文件转移的sh脚本

发布时间: 2012-07-23 09:42:19 作者: rapoo

linux下实现文件转移的sh脚本

实现目标:CN目录下有若干文件夹,并且每个文件夹中有一系列以CN开头的子文件夹,现要求将CN开头的这些子文件夹实现按文件夹名进行组织存放,例如将/home/CN/temp/CN20081478023的文件夹存放到/home/CN/2008/1478/CN20081478023,则shell命令如下:

#!/bin/bash# forcount=1for 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 fidone >output.txt
?

读书人网 >UNIXLINUX

热点推荐