/ factorpad.com / tech / linux-essentials / comm-command.html
An ad-free and cookie-free website.
Beginner
Learn to compare two files at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux comm Command Summary with Examples (3:36)
Our thirty-fifth word, or command to memorize is
comm
from our category
Text.
comm
allows you to simply compare
two files.
-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.
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
.
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.
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.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you like the videos, check out other learning resources at our YouTube Channel.
diff
command,
hit Back.sdiff
, click Next./ factorpad.com / tech / linux-essentials / comm-command.html
A newly-updated free resource. Connect and refer a friend today.