#!/bin/sh
##################################
# cp source file to new dir
#
##################################
ROOT_DIR='/home1/www/webpub'
REPLACE_ROOT_DIR='\/home1\/www\/webpub'
FIND_EXT_NAME='*.inc'
FIND_EXT_NAME2='*.INC'
FIND_TEMP_FILE='/tmp/t_inc'
KEY_WORD='market.52pk.com'
#find $ROOT_DIR -name "$FIND_EXT_NAME" -exec grep "$KEY_WORD" {} \;> $FIND_TEMP_FILE
#find $ROOT_DIR -name "$FIND_EXT_NAME2" -exec grep "$KEY_WORD" {} \; >> $FIND_TEMP_FILE
grep -Frl --include="$FIND_EXT_NAME" --include="$FIND_EXT_NAME2" 'market.52pk.com' $ROOT_DIR > $FIND_TEMP_FILE
while read line
do
DIR_NAME=$(dirname $line)
echo $DIR_NAME
NEW_DIR_NAME=$(echo $DIR_NAME | sed -e "s#$REPLACE_ROOT_DIR##g")
echo $NEW_DIR_NAME
if [ ! -d $NEW_DIR_NAME ]
then
mkdir -p $NEW_DIR_NAME
fi
cp -a $line $NEW_DIR_NAME
done < $FIND_TEMP_FILE
rm -rf $FIND_TEMP_FILE
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/456619