Chinaunix首页 | 论坛 | 博客
  • 博客访问: 515490
  • 博文数量: 87
  • 博客积分: 4086
  • 博客等级: 上校
  • 技术积分: 900
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-23 15:55
文章分类

全部博文(87)

文章存档

2012年(3)

2010年(13)

2009年(7)

2008年(64)

我的朋友

分类: LINUX

2010-11-11 16:09:18

两个文件夹下面的文件个数及其名称完全一样,但是内容有的可能不一样,这个脚本遍历文件夹下的所有子文件夹,包括嵌套多层的,然后使用linux系统的diff命令对两个名称一样的文件进行比较,脚本如下:

#!/bin/sh


if [ $# -ne 2 ]

then
    echo Usage: compare.sh fold_name_1 fold_name_2
    exit
fi

if [ ! -d $1 ]
then
    echo $1 is not a
    exit
fi

if [ ! -d $2 ]
then
    echo $2 is not a
    exit
fi

fold1=$(echo $1 | sed 's|\(^[^/]*\).*|\1|')
fold2=$(echo $2 | sed 's|\(^[^/]*\).*|\1|')

compareFOLD()
{
    for file in $1/*
    do
        if [ -d $file ] then
            compareFOLD $file
        elif [ -f $file ]
        then
            if [ ! -L $file ]
            then
                file2=$(echo $file | sed "s|^.[^/]*\(.*\)|$fold2\1|")
                diff $file $file2
                if [ $? -ne 0 ]
                then
                    echo -e "\033[32m"$file
                    echo $file2
                    echo -e "\033[0m"---------------------------------------------------------------------
                fi
            fi
        fi
    done
}

compareFOLD $fold1
            


阅读(11330) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-14 14:48:18

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com