日期:2014-05-16  浏览次数:20646 次

复制文件的脚本(linux+windowx)
功能:把指定文件夹(不包括)下的所有东西复制到指定文件夹下。
      在产品发布的时候,某些不共享的配置文件可以通过此脚本在项目第一次发布的时候生成。

windows版本(当前目录下resources)
rem @echo off
::cd ../../..
echo cd
set root_dir=%cd%\..\..\..
echo %root_dir%
set toPath=%root_dir%\resources
xcopy /S/Y res_module %toPath%
pause


linux版本
#!/bin/sh:/bin/bash
export PATH=/usr/bin:/bin:/sbin:/usr/sbin:$PATH
cur_dir=`pwd`
root_dir=`dirname $0`
echo "tools_path:"${root_dir}
toPath=${root_dir}/../classes
echo  "target_path:"${toPath}

cd ${root_dir}
tmp_dir=${root_dir}/"tempDir"
rm -fr $tmp_dir
mkdir $tmp_dir
cp -r res_module/* $tmp_dir
find $tmp_dir -name ".svn" | xargs -i rm -fr {} \ ; 
cp -r $tmp_dir/* ${toPath}

rm -fr $tmp_dir

cd $cur_dir
echo "deploy succ!"


很久没写shell脚本了,所以写的有点绕,采用下面这个指令或许要简洁点:
find dir -name "*.txt" -exec cp --parents {}  tmp/ \;


另外,如果shell在运行时报错误:bash command not found,加上export path那行就行了。
想彻底解决的话,在系统环境变量中修改下好了。
参考文章:http://hi.baidu.com/man_zxc/item/c9dc0517020cd9ddbe9042a1