← Files & Text
Linux · Files & Text

How to compare files in Linux

Compare two files line by line with diff, find common lines with comm, and check if files are identical with cmp.


See how two files differ. diff shows line changes (use -u for the familiar unified format); comm compares sorted files; cmp reports the first differing byte.

# Unified diff (what changed)
diff -u file1 file2

# Side by side
diff -y file1 file2

# Common / unique lines (inputs must be sorted)
comm <(sort file1) <(sort file2)

# Byte-for-byte identical?
cmp file1 file2
LinuxdiffCompare