comm - compare two sorted files line by line
| Use Case | Command | Description |
|---|---|---|
| πΉ Common lines only | comm -12 file1 file2 | Suppress columns 1 & 2 (unique lines), leaving only lines present in both files |
| πΉ Lines unique to FILE1 | comm -23 file1 file2 | Suppress columns 2 & 3, showing lines only in FILE1 |
| πΉ Lines unique to FILE2 | comm -13 file1 file2 | Suppress columns 1 & 3, showing lines only in FILE2 |
| πΉ Lines unique to either file (no common lines) | comm -3 file1 file2 | Suppress column 3 (common lines), showing lines unique to each file |
| πΉ Verify sorted order | comm --check-order file1 file2 | Check that input files are correctly sorted |
| πΉ NULβterminated lines | comm -z file1 file2 | Use NUL as line delimiter |
| πΉ Summary only | comm --total file1 file2 | Output a summary of counts |
comm [OPTION]... FILE1 FILE2
Compare sorted files FILE1 and FILE2 line by line.
When FILE1 or FILE2 (not both) is -, read standard input.
With no options, produce threeβcolumn output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files.
-1suppress column 1 (lines unique to FILE1)
-2suppress column 2 (lines unique to FILE2)
-3suppress column 3 (lines that appear in both files)
--check-ordercheck that the input is correctly sorted, even if all input lines are pairable
--nocheck-orderdo not check that the input is correctly sorted
--output-delimiter=STRseparate columns with STR
--totaloutput a summary
-z, --zero-terminatedline delimiter is NUL, not newline
--helpdisplay this help and exit
--versionoutput version information and exit
Note: comparisons honor the rules specified by 'LC_COLLATE'.
comm -12 file1 file2
πΉ Print only lines present in both file1 and file2.
comm -3 file1 file2
πΉ Print lines in file1 not in file2, and vice versa.
Written by Richard M. Stallman and David MacKenzie.
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Copyright Β© 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to
the extent permitted by law.
Full documentation <https://www.gnu.org/software/coreutils/comm>
or available locally via: info '(coreutils) comm invocation'
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 17:27 @2600:1f28:365:80b0:f8a4:e764:d6bb:8e66
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format