comm -23: set operations on sorted files

Use comm with column suppressions to compute set differences and intersections between sorted files on Linux.

LinuxsetsdiffcompareLow risk
Run comm -23 A B for lines only in A, comm -13 for lines only in B, and comm -12 for lines in both.

01Command

Command
$ comm -23 <(sort old.list) <(sort new.list)

02What it does

comm outputs three columns — lines unique to file1, unique to file2, and common — and the numbered flags simply hide columns: -12 gives the intersection, -23 gives 'in A but not B' (a true set difference). It requires both inputs to be sorted, so process substitution <(sort file) is the usual wrapper. This is the reliable way to answer 'which entries disappeared between yesterday's and today's lists?'

03Risk

RiskLow risk
!Warning: Both files must be sorted with the same collation — use LC_ALL=C sort on both sides or results will be silently wrong.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • comm(1) — Arch Linux manual
    Arch Linux · technical · 2026-09-17
    Evidence: -1/-2/-3 suppress column 1 (file1-only), 2 (file2-only), 3 (common); inputs must be sorted
  • comm(1P) — POSIX manual page
    man7.org · technical · 2026-09-17
    Evidence: POSIX defines the three-column output and the requirement that files be sorted with LC_ALL consistency

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions