What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use comm to compare two sorted line-based inputs: it reports lines found only in the first input, only in the second, and in both. To compare directory entries, first create sorted name listings; comm does not traverse directory trees or compare file contents.
What comm compares
GNU Coreutils describes comm as writing lines common to, and unique to, two input files. It compares lines, not arbitrary unsorted records or structured fields. With no options, output has three tab-separated columns in this order:
- Lines unique to the first input.
- Lines unique to the second input.
- Lines present in both inputs.
The columns retain their positions when output is printed; suppressing a column also removes its separator. See the GNU Coreutils 9.11 comm manual and the Linux comm(1) manual.
Sort both inputs compatibly first
Each input must be sorted according to the collation order used by comm. A reliable way to avoid locale mismatches is to sort both files and run the comparison under the same C locale:
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
LC_ALL=C sort file1 > file1.sorted
LC_ALL=C sort file2 > file2.sorted
LC_ALL=C comm file1.sorted file2.sorted
For already-sorted files, check them using the same locale:
LC_ALL=C sort -c file1
LC_ALL=C sort -c file2
sort -c checks ordering and reports the first out-of-order line. Sorting under one locale and comparing under another can produce an ordering diagnostic or misleading results. GNU documents that sort without options creates input suitable for comm; see GNU Coreutils: sort invocation.
Choose which lines to show
The flags -1, -2, and -3 suppress the first, second, and third columns, respectively. Combine them to select the category you need:
| Command | Output |
|---|---|
comm file1.sorted file2.sorted |
All three categories: first-only, second-only, and shared lines. |
comm -12 file1.sorted file2.sorted |
Lines shared by both inputs. |
comm -23 file1.sorted file2.sorted |
Lines found only in the first input. |
comm -13 file1.sorted file2.sorted |
Lines found only in the second input. |
comm -3 file1.sorted file2.sorted |
Lines unique to either input; shared lines are omitted. |
With -3, a leading tab may appear where the suppressed first column would have been. Account for it if another command or script will parse the output. The column behavior is documented by POSIX.1-2017 comm(1p) and the GNU manual.
Use standard input for one side
GNU comm accepts - for an operand to read that input from standard input. For example, generate and sort one side of a comparison in a pipeline while using a prepared file for the other:
printf '%sn' apple pear plum | LC_ALL=C sort | LC_ALL=C comm - file.sorted
The generated stream and file must use compatible ordering. POSIX says using standard input for both operands, or using the same special input source for both, has undefined results; use two distinct inputs instead.
Rank #4
Compare directory entry names
comm takes line streams, not directory paths to traverse. For a basic comparison of immediate entry names, make one newline-delimited listing per directory, sort both with the same locale, then compare the listings:
LC_ALL=C ls -1 dir1 | LC_ALL=C sort > dir1.names
LC_ALL=C ls -1 dir2 | LC_ALL=C sort > dir2.names
LC_ALL=C comm -3 dir1.names dir2.names
This compares listed names only. It does not compare file contents, metadata, or nested directory trees. Also, filenames can contain newline characters, so a one-name-per-line listing cannot safely represent every possible filename. For robust filename handling, use NUL-delimited tools and check their GNU-specific options rather than treating this basic comm workflow as fully filename-safe.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Best Value
Interpret results and exit status correctly
comm‘s exit status does not depend on whether the inputs differ. A zero exit status does not mean the files contain only shared lines, and a nonzero status should not be treated as a signal that differences were found. Inspect the output, or build an explicit test based on the output your script expects.
If your goal is visual comparison, recursive directory-tree comparison, or finding content differences between corresponding files, comm is not the right comparison method: it reports membership of complete lines in two sorted streams.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

