File Viewing & Editing

comm

Compare two sorted files line by line, showing unique and common lines.

Synopsis

syntax
comm [OPTION]... FILE1 FILE2

Examples

Show three-column comparison
comm file1.txt file2.txt
Show only lines common to both files
comm -12 sorted1.txt sorted2.txt
Show lines only in first file
comm -23 all.txt subset.txt

Common options

FlagDescription
-1Suppress lines unique to file 1
-2Suppress lines unique to file 2
-3Suppress lines common to both

About comm

The `comm` command compare two sorted files line by line, showing unique and common lines. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.

Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.

The command accepts 3 commonly used flags shown above, though the full set of options is available in the man page (`man comm`). The 3 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More File Viewing & Editing Commands

Other commands in the File Viewing & Editing category

Related tools