Purpose and Requirements:
When porting, you need to integrate the new content in the root filesystem rootfs1 into the ROOTFS2, but not the things rootfs2. That is, you can only compare the similarities and differences of two file systems, moving more than 2 out of 1 to 2.
Difficulties:
If you have the same subdirectory in the directory, make the subdirectories meet the above requirements.
The finishing touches:
Shell recursive invocation, referring to binary tree depth-first traversal.
Real:
1#!/bin/Bash2 3 Cpdifffile ()4 {5 6dir1=$17dir2=$28Files1= 'ls$DIR 1 '9#files2 = 'ls$DIR 2 'Ten forFile1inch$files 1 One Do A ls$DIR 2/$file 1 >/dev/NULL 2>&1 - if[$?-eq0 ] - Then the Echo$DIR 2 havefile$file 1 - Else - EchoWouldCP$DIR 1/$file 1 to $DIR 2 - CP-a $DIR 1/$file 1 $DIR 2/ + fi - Done + } A at Cpsamedir () - { -Cpdifffile $1$2 -Subdirs1= 'ls-L $1|grep "^d"|awk-f\'{print $9}'` -Subdirs2= 'ls-L $2|grep "^d"|awk-f\'{print $9}'` - unset samedirs # #注意, here to empty the array, otherwise the result of the last call is saved here will form a ring, a dead loop inI=0 - forSubDir1inch$subdirs 1 to Do + ls$2/$subdir 1 >/dev/NULL 2>&1 - if[$?-eq0 ] the Then *samedirs[i]=$subdir 1 $Let i++Panax Notoginseng - Else the Echo$1Havedir$subdir 1, but $2Not . + fi A Done the Echo "Bettenw $ and $, the same dir is:" + Echo${samedirs[@]} - $ forSamedirinch${samedirs[@]} $ Do - Echo "Now oparate $1/$samedir and $2/$samedir" -Cpsamedir $1/$samedir $2/$samedir the Done - Wuyi the - } Wu - Main () About { $Cpsamedir $1$2 - - } - AMain $1$2
Shell function recursive call implements a comparative copy of the directory