本文記錄下,曾經使用的sh腳本之一,時間太久忘完了,記錄下。
#!/bin/bash
#
#example to use this script.
#source to_find_prop_files.sh ~/workspace/org_source_code/out ~/workspace/tsrc_code/out~/workspace/to_vrz_src_code/out
#arg1's src is contain main files more libs
#arg2's src is not contain vendor path.
#the result path is current path
#功能:比較參數1,2兩個路徑中到文件,把參數1路徑多出到文件,按完整路徑,拷貝到result目錄下
#
dir="result"
dir1=$1
dir2=$2
if [ -e $dir ]; then
rm -rf $dir
echo "remove old result and create newer!"
mkdir $dir
touch $dir/same_path.log
touch $dir/props_files.log
else
echo "create result path!"
mkdir $dir
touch $dir/same_path.log
touch $dir/props_files.log
fi
function find_props(){
for element in `ls $1`
do
dir1_or_file=$1"/"$element
if [ -d $dir1_or_file ]; then
dir2_or_file=$2"/"$element
if [ -e $dir2_or_file ]; then
find_props $dir1_or_file $dir2_or_file
else
sub_path=$dir"/"$2
mkdir -p $sub_path
cp -rf $dir1_or_file $sub_path
echo "$dir1_or_file" >> $dir/props_files.log
fi
else
file2=$2"/"$element
if [ -e $file2 ]; then
echo "$file2" >> $dir/same_path.log
else
sub_path=$dir"/"$2
mkdir -p $sub_path
cp -rf $dir1_or_file $sub_path
echo "$dir1_or_file" >> $dir/props_files.log
echo "copy new files please wait..."
fi
fi
done
}
find_props $dir1 $dir2
保存爲.sh即可。在linux系統下使用。