Text and processing
The comm command
Compares two sorted files and shows in columns which lines are only in the first, only in the second or shared.
Syntax
comm [-1] [-2] [-3] archivo1 archivo2Most useful options
-1Hides the first file's column-2Hides the second's column-3Hides the shared columnCopy-ready examples
$ printf 'a\nb\n' > c1.txt && printf 'b\nc\n' > c2.txt && comm c1.txt c2.txtCompare two lists$ printf 'a\nb\n' > c1.txt && printf 'b\nc\n' > c2.txt && comm -12 c1.txt c2.txtOnly the sharedYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- The files must be sorted: otherwise the result is wrong. Use sort first.
FAQ
How do I get only what is in both?
With comm -12: it hides the first and second columns.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course