FactorPad
Build a Better Process

Linx comm Command Summary with Examples

Linux comm allows you to simply compare two files.
  1. Purpose - Learn what comm is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with comm.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux comm, 35 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / comm-command.html


An ad-free and cookie-free website.


Examples of the Linux comm Command

Beginner

Learn to compare two files at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux comm Command Summary with Examples (3:36)

Video Script

The Command and Why You Need It

Our thirty-fifth word, or command to memorize is comm from our category Text.

comm allows you to simply compare two files.

Common Linux comm Options
-options description
-1 Supress lines unique to first file
-2 Supress lines unique to second file
-3 Supress lines that appear in both files

Recall that the diff command had many bells and whistles, so comm is an alternative.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The comm command has 8 options, instead of the nearly 50 available with diff. And the arguments are the files you'd like to compare.

Like most commands, help is available with double-dash --help. The output here has three columns. First, lines unique to the first file. Second, those unique to the second. Then lines in both files. So with these options you can eliminate any of the default columns.

So why is comm an important command? Well, you might be looking for an uncomplicated way to compare files. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Earlier we created two text files using a directory listing. Let's compare them without options, using comm video34.txt video35.txt.

$ comm video34.txt video35.txt Oct 4:video05.txt Oct 10:video11.txt Oct 10:video16.txt Oct 12:video19.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video23.txt Oct 15:video24.txt Oct 15:video26.txt Oct 15:video27.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video33.txt Oct 9:video16.txt comm: file 1 is not in sorted order Oct 12:video19.txt Oct 12:video20.txt Oct 13:video21.txt Oct 13:video23.txt Oct 15:video24.txt Oct 15:video26.txt Oct 15:video27.txt Oct 17:video31.txt Oct 18:video32.txt Oct 18:video33.txt

Here (first column) we have unique to the first file. The second column unique to the second and here (third column) what is in common. Are you confused? Well, if you saw the last video recall that video34.txt had a line that wasn't in the proper order, as noted here (line noting file 1 is not in sorted order) so all of these (first column) show up as differences. That's a hassle huh?

And last, let's see what's in common here, by adding the -12 option, suppressing these two columns (1 and 2) and then rerun.

$ comm -12 video34.txt video35.txt Oct 4:video05.txt Oct 10:video11.txt comm: file 1 is not in sorted order

So we know what matches now, but have some work to do. Then the lesson here is to make sure files are sorted, or comm won't be of much help.

A Final Tip

Okay now you know how to use comm. And you know the syntax for commands, options and arguments.

One last tip about the comm command. So comm provides a second option, but you may prefer diff or a third option introduced next.

Okay, thanks for visiting today. I hope this was a helpful introduction to the comm command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If you like the videos, check out other learning resources at our YouTube Channel.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / comm-command.html


linux comm command
comm linux
linux comm
unix comm
comm unix
linux comm examples
comm files
comm command
linux compare two files
linux compare line by line
comm command syntax
compare files
linux comm summary
linux comm options
linux comm tutorial
man comm
compare documents
compare two text files
compare tool
compare 2 files
compare docs
linux compare two files

A newly-updated free resource. Connect and refer a friend today.