首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

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

2012-07-23 
linux下实现文件转移的sh脚本实现目标:CN目录下有若干文件夹,并且每个文件夹中有一系列以CN开头的子文件夹

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
?

热点排行