Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15177482
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-03 10:50:07

作者:devel
算法:
1.先find /pathname -print >filea #获取两个夹里所有文件的全名。
2,比较文件,先删去要的文件夹里多余的文件。接着重新获得需要同步的文件夹里所有文件的全名。
3.比较文件,把源文件夹里增加的文件CP到要同步的文件夹中。
这个是同步/share目录里的所有文件,需要到/mnt/d/share
代码:
#!/bin/bash
/dev/hda6 /mnt/d 2>/dev/null ; unalias rm cp
rm /share/c/app/*o /share/c/tmp/*o /share/c/app/*core /share/c/tmp/*core /share/c/app/a.out /share/c/tmp/a.out
find /share -print >/tmp/.share_    #把/share的所有文件的全名保存到/tmp/.share_
find /mnt/d/share -print |sed 's/\/mnt\/d//g' >/tmp/.d_
chmod 700 /tmp/.share_ /tmp/.d_
count=0
for i in $(comm -23 /tmp/.d_ /tmp/.share_) ; do     #比较两个文件里/tmp.d_ 与/tmp./share_的不同。
echo "/mnt/d$i"
rm "/mnt/d$i" ; count=$((count+1))    #删除/mnt/d/share/*里的多余的文件和计数。
done    #for command ;do command ; done的循环到此结束。
echo "del $count file at /mnt/d/share/"
find /mnt/d/share -print |sed 's/\/mnt\/d//g' >/tmp/.d_ ; count=0    #重新获得文件的全名。初始化计数器。
for i in $(comm -23 /tmp/.share_ /tmp/.d_) ; do
echo $i
cp $i "/mnt/d$i" ; count=$((count+1))    #备份/share里新增加的文件到/mnt/d/share,同时计数。
done
echo "already copied $count file from /share to /mnt/d/share " ;sync
umount /mnt/d 2>/dev/null
echo done
阅读(2232) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~