shell实现把一个目录的文件拷贝到另一个目录
shell实现把一个目录的文件拷贝到另一个目录,如果文件重复,则覆盖之。
?
version 1:
?
#!/bin/bashif [ $# -lt 2 ]; then echo "Error !!!This shell file is used to copy files under a directory to another. Please pass two arguments to it.The first argument is for the source directory and the second for destination directory " > /dev/ttyexit 1fisrc=$1des=$2tsrc=$(echo $src | awk 'gsub("/", "\/")')tdes=$(echo $des | awk 'gsub("/", "\/")')#echo $tsrcfind $src -type f | while read linedotf=$(echo $line | sed "s/$tsrc/$tdes/")td=$(dirname $tf)if [ ! -d $td ]; thenmkdir -p $tdficp $line $tfdone?
version 2:
#!/bin/bashif [ $# -lt 2 ]; then echo "Error !!!This shell file is used to copy files under a directory to another. Please pass two arguments to it.The first argument is for the source directory and the second for destination directory " > /dev/ttyexit 1fisrc=$1des=$2src_len=$(echo $src | awk '{ print length($1) }')let "src_len=$src_len + 1"find $src -type f | while read linedotf=$des$(echo $line | awk -v pos=$src_len '{ print substr($1, pos) }')td=$(dirname $tf)if [ ! -d $td ]; thenmkdir -p $tdficp $line $tfdone?