Learn to compare two files at the Linux command line.
Linux comm command summary with examples (3:36)
Videos can also be accessed from the YouTube Playlist.
Our thirty-fifth word, or command to memorize is
comm from our category
comm allows you to simply compare
Recall that the
diff command had many
bells and whistles, so
comm is an
Before we start, it helps to think of commands as mini programs and
most follow this structure:
command -option(s) argument(s).
comm command has
8 options, instead of the nearly 50
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
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
And you know the syntax for commands, options and arguments.
One last tip about the
comm provides a second option, but
you may prefer
diff or a third option
Okay, thanks for visiting today. I hope this was a helpful
introduction to the
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, subscribe to the YouTube Channel here.
diffcommand, hit Back.
sdiff, click Next.