Linux

Compare directories using diff in Linux

To compare two directories, we are going to use diff.

diff dir1/ dir2/

If you are not interested in file differences, add the -q parameter.

diff -q dir1/ dir2/

To search and compare recursively, add -r parameter.

diff -qr dir1/ dir2/

To sort results use sort command.

diff -qr dir1/ dir2/ | sort

Redirect comparison results to file.

diff -qr dir1/ dir2/ | sort > diff_results