How to use “diff” utility effectively
The command line tool “diff” helps you find differences between two files or directories. It also can report the differences between two directories including all files and sub directories recursively.
Compute differences between two files:
[neo@techpulp ~]# diff animals1.txt animals2.txt 4a5 > crane 8,9d8 < tiger < panda 16c15 < lion --- > lion roars [neo@techpulp ~]#
Whatever starts with “<” is the change in first file and whatever starts with “>” is the change in second file.
Compute differences between two files but ignore white spaces and blank lines:
[neo@techpulp ~]# diff -b -B animals1.txt animals2.txt
Compute differences between two directories:
[neo@techpulp ~]# diff dir1 dir2
Compute differences between two directories recursively:
[neo@techpulp ~]# diff -r dir1 dir2
Compute differences between two directories recursively but ignore anything that matches CVS:
[neo@techpulp ~]# diff -r dir1 dir2 --exclude=CVS
Compute differences between two directories recursively but ignore anything that matches CVS and ignore white space and blank lines:
[neo@techpulp ~]# diff -r -b -B dir1 dir2 --exclude=CVS

