Implement a shell script for folder Synchronization
Algorithm:
1. First find/pathname-print> filea # Get the full names of all files in the two folders. <Br/> 2. Compare files. Delete unnecessary files in the folder to be synchronized. Then obtain the full names of all files in the folder to be synchronized. <Br/> 3. Compare files and CP the files added to the source folder to be synchronized. <Br/>
This script is used to synchronize all the files in the/share directory and needs to be backed up to/mnt/D/share.
#! /Bin/bash </P> <p> Mount/dev/hda6/mnt/D 2>/dev/NULL; unalias rm cp <br/> RM/share/C/APP/* o/share/C/tmp/* o/share/C/APP/* Core/share/C/ TMP/* Core/share/C/APP/. out/share/C/tmp/. out <br/> Find/share-print>/tmp /. share _ # Save the full name of all/share files to/tmp /. share _ </P> <p> Find/mnt/D/share-print | SED's // MNT // D // G'>/tmp /. D _ <br/> chmod 700/tmp /. share _/tmp /. D _ <br/> COUNT = 0 <br/> for I in $ (Comm-23/tmp /. D _/T MP/. Share _); do # compare the differences between/tmp. D _ and/tmp./share _ in the two files. </P> <p> echo "/mnt/d $ I" <br/> RM "/mnt/d $ I"; Count = $ (count + 1 )) # Delete unnecessary files and counts in/mnt/D/share. </P> <p> done # For command; do command; the cycle of done ends here. </P> <p> echo "del $ count file at/mnt/D/share/" <br/> Find/mnt/D/share-print | SED's/ // MNT // D // G'>/tmp /. D _; Count = 0 # obtain the full name of the file again. Initialize the counter. </P> <p> for I in $ (Comm-23/tmp /. share _/tmp /. D _); DO <br/> echo $ I <br/> CP $ I "/mnt/d $ I"; Count = $ (count + 1 )) # Back up the newly added files in/share to/mnt/D/share and count them at the same time. </P> <p> done <br/> echo "already copied $ count file from/share to/mnt/D/share "; sync <br/> umount/mnt/D 2>/dev/null <br/> echo done </P> <p>