diff is a tool used to compare the contents of two files and highlight the differences between them. It is especially useful for identifying changes made to a file over time, comparing two different versions of the same file, or identifying differences between files with similar names or contents.
Basic Syntax
diff [options] file1 file2
Here, file1 and file2 are the names of the two files to be compared. If no options are specified, the diff command will display the differences between the two files in a side-by-side format.
Commonly Used Options
-
-c: This option displays the differences between the two files in a unified context format. -
-r: This option performs a recursive comparison of directories and their contents. -
-q: This option displays only whether the two files are different or not, without showing the details of the differences. -
-i: This option ignores changes in case when comparing two files. -
-w: This option ignores white spaces when comparing two files. -
-B: This option ignores changes in the amount of white space when comparing two files.
Useful Examples
-
diff file1 file2: This displays the differences between the two files file1 and file2 in a side-by-side format. -
diff -c file1 file2: This displays the differences between the two files file1 and file2 in a unified context format. -
diff -r directory1 directory2: This performs a recursive comparison of the directories directory1 and directory2, and displays the differences between the files in them. -
diff -q file1 file2: This displays only whether the two files file1 and file2 are different or not, without showing the details of the differences. -
diff -i file1 file2: This compares the two files file1 and file2, ignoring changes in case. -
diff -w file1 file2: This compares the two files file1 and file2, ignoring white spaces. -
diff -B file1 file2: This compares the two files file1 and file2, ignoring changes in the amount of white space.
Leave a Reply