copy and paste the following in a file named compare:
=============================================
#!/bin/bash
#
# cmptree: compare directory trees recursively and report the differences.
function gettype () {
if [ -L $1 ]; then
echo "softlink"
elif [ -f $1 ]; then
echo "file"
elif [ -d $1 ]; then
echo "directory"
else
echo "unknown"
fi
}
function exists () {
if [ -e $1 -o -L $1 ]; then
return 0;
else
echo "$1 does not exist."
return 1;
fi
}
function comparefile () {
cmp -s $1 $2
if [ $? -gt 0 ]; then
echo "$1 different from $2"
# else
# echo "$1 same as $2"
fi
return
}
function comparedirectory () {
local result=0
for i in `(ls -A $1 && ls -A $2) | sort | uniq`; do
compare $1/$i $2/$i || result=1
done
return $result
}
function comparesoftlink () {
local dest1=`ls -l $1 | awk '{ print $11 }'`
local dest2=`ls -l $2 | awk '{ print $11 }'`
if [ $dest1 = $dest2 ]; then
return 0
else
echo "different link targets $1 -> $dest1, $2 -> $dest2"
return 1
fi
}
# compare a file, directory, or softlink
function compare () {
(exists $1 && exists $2) || return 1;
local type1=$(gettype $1)
local type2=$(gettype $2)
if [ $type1 = $type2 ]; then
case $type1 in
file)
comparefile $1 $2
;;
directory)
comparedirectory $1 $2
;;
softlink)
comparesoftlink $1 $2
;;
*)
echo "$1 of unknown type"
false
;;
esac
else
echo "type mismatch: $type1 ($1) and $type2 ($2)."
false
fi
return
}
if [ 2 -ne $# ]; then
cat << EOU
Usage: $0 dir1 dir2
Compare directory trees:
files are binary compared (cmp)
directories are checked for identical content
soft links are checked for identical targets
EOU
exit 10
fi
compare $1 $2
exit $?
===================================================
now execute it as
compare dir1 dir2
On 6/2/05, Abhinav Jain <[EMAIL PROTECTED]> wrote:
> Hi
> I am a newbie in the field of open source . I was trying to make a
> script that could extend the diff command so that it could take in two
> directories with same structure and file names and find the diff
> between all the files in them . Currently the command can only accept
> two files whose diffs are to be found . What I want to make is
> something like a "cvs diff" but without the se of cvs .
> I was able to make one that could find the diffs of files in a single
> directory . I want to extend it to include the subdirectories . My
> code is as follows :
>
> #!/bin/sh
>
> ls > Result
>
> cat Result | \
> while read line
> do
> diff $line <relative path to the other directory>/$line
> done
>
> Earnest Regards
> Abhinav
>
>
>
> --
> Abhinav Jain
> UnderGraduate Student
> Department of Computer Science and Engineering
> Institute of Technology , Banaras Hindu University
> [EMAIL PROTECTED]
>
> _______________________________________________
> ilugd mailinglist -- [email protected]
> http://frodo.hserus.net/mailman/listinfo/ilugd
> Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
> http://www.mail-archive.com/[email protected]/
>
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/