The diff command can be used to determine if two different files or directories contain any differences.
Let's say file1 contains "Hello World" and file2 contains "How are you today". The diff command will identify that the content of file1 and file2 are different.
~]# diff file1 file2 < Lines that begin with < exist in file1 but not in file2 > Lines that begin with > exist in file2 but not in file1
By default, the diff command will compare lines in each file. For example, in line 1 in file 1 is not exactly the same as line 1 in file 2, then the diff command will spot these as different. Let's say file 1 contains "Hello World", and you want to determine if "Hello World" exists on any line in file 2. The -c option will accomplish this goal.
~]# diff -c file1 file2 ! Lines that begin with ! exist in file1 but not in file2 Lines that begin with a white space exist in file2 but not in file1
You can list all of the differences between files in two different directories.
~]# diff /path/to/directory1 /path/to/directory2
The -r (recursive) option can be used to search for files that differ at and below a certain directory.
~]# diff -r /path/to/directory1 /path/to/directory2
Instead of listing all of the differences between files, you can instead just list the files that are in directory "a" but not in directory "b" and vice versa, and the files that are in both directories but have different content.
~]# diff --brief -r /path/to/directory1 /path/to/directory2