-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir-diff.sh
More file actions
executable file
·48 lines (40 loc) · 1.15 KB
/
dir-diff.sh
File metadata and controls
executable file
·48 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
# Created on 2011-08-11 by Julien MOREAU aka PixEye
cmd=`basename "$0"`
echo "\ntest"|grep ntest >> /dev/null && e="-e" # is the "-e" echo option needed?
if [ "$#" -ne 2 ]
then echo "Usage: $cmd <dir1> <dir2>" ; return 2
fi
min_diff=999999 # big value
less_diff_entry=''
dir1="$1" ; dir2="$2"
tmp_file="/tmp/$cmd"
if [ ! -d "$dir1" ]
then echo "'$dir1' is not a directory!" ; return 3
fi
if [ ! -d "$dir2" ]
then echo "'$dir2' is not a directory!" ; return 4
fi
echo $e "Going to: \c" # the "cd" bellow is verbose on my linux box
cd "$dir1" || return $?
ls -d */ |while read f
do
n=`diff -r "$f" "../$dir2/$f"|wc -l`
echo "Debug: $n diff between '$f' & '../$dir2/$f'." # can be commented
if [ $n -lt $min_diff ]
# if [ $n -gt 0 -a $n -lt $min_diff ]
then min_diff=$n ; less_diff_entry="$f"
# a temporary file is needed to keep memory from the while namespace:
echo $less_diff_entry > "$tmp_file"
# echo "Debug: min_diff=$min_diff ; less_diff_entry='$f'" # can be commented
fi
done
if test -r "$tmp_file"
then
echo $e "Less diff entry is: \c"
cat "$tmp_file"
rm "$tmp_file"
else
echo "Did not find any difference!"
return 1
fi