Skip to content

Linux comm Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux comm Guide

Complete beginner-friendly guide to comm on Linux, covering Arch Linux, CachyOS, and other distributions including comparing sorted files, finding common lines, and file comparison.


Table of Contents

  1. Understanding comm
  2. comm Basics
  3. Comparing Files
  4. Output Columns
  5. Troubleshooting

Understanding comm

What is comm?

comm compares two sorted files line by line.

Uses:

  • Compare files: Find differences
  • Common lines: Find shared lines
  • Unique lines: Find unique lines
  • File comparison: Compare sorted files

Why it matters:

  • File comparison: Compare sorted files
  • Data analysis: Find common/unique data
  • Set operations: Perform set operations

comm Basics

Compare Files

Basic usage:

# Compare files (must be sorted)
comm file1.txt file2.txt

# Shows three columns

Output Format

Three columns:

# Column 1: Lines only in file1
# Column 2: Lines only in file2
# Column 3: Lines in both files

Comparing Files

Suppress Columns

Hide columns:

# Suppress column 1 (file1 only)
comm -1 file1.txt file2.txt

# Suppress column 2 (file2 only)
comm -2 file1.txt file2.txt

# Suppress column 3 (common lines)
comm -3 file1.txt file2.txt

Common Lines Only

Show common:

# Only common lines
comm -12 file1.txt file2.txt

# -1 = suppress col1, -2 = suppress col2

Output Columns

Unique Lines

File1 only:

# Lines only in file1
comm -23 file1.txt file2.txt

# -2 = suppress col2, -3 = suppress col3

All Unique

All unique lines:

# All unique lines (not common)
comm -3 file1.txt file2.txt | tr -d '\t'

# Shows lines in either file but not both

Troubleshooting

Files Not Sorted

Sort first:

# Sort files first
sort file1.txt > file1.sorted.txt
sort file2.txt > file2.sorted.txt
comm file1.sorted.txt file2.sorted.txt

Summary

This guide covered comm usage, file comparison, and set operations for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally