nolo41
March 27, 2016, 12:59pm
1
Hello,
I'd want to compare the content of 2 directories in unix.
I use the diff command like this:
diff /home/user/AAAAA /home/user/BBBBB
It works fine, but when a same file is in both directories and they are diferents, I'd want to see only that it is diferent and not all diferencies.
I tried:
diff -c but it doesn't works.
Could anyone help me please ?
thanks in advance
If GNU diff is available to you, you could use the --brief option to do what you want.
jgt
March 27, 2016, 3:36pm
4
Or the long way.
for file in `ls dir1`
do
if [ -r dir2/$file ]
then
diff $file dir2/$file >/dev/null
if [ $? -eq 1 ]
echo $file is diff
else
echo $file is same in both directories
fi
else
echo $file does not exist id dir2
fi
done
then reverse dir1 and dir2 to find files that exist in dir2 that do not exist in dir1
Aia
March 27, 2016, 4:16pm
5
jgt:
Or the long way.
for file in `ls dir1`
do
if [ -r dir2/$file ]
then
diff $file dir2/$file >/dev/null
if [ $? -eq 1 ]
echo $file is diff
else
echo $file is same in both directories
fi
else
echo $file does not exist id dir2
fi
done
then reverse dir1 and dir2 to find files that exist in dir2 that do not exist in dir1
This could be a poor choice, since it will break if file names contain spaces.