With no options, comm produces three-column output. Column one contains lines unique to file f1, column two contains lines unique to file f2, and column three contains lines common to both files.
-1 suppress column 1 (lines unique to file f1)
-2 suppress column 2 (lines unique to file file f2)
-3 suppress column 3 (lines that appear in both files)
comm -12 f1 f2
prints lines in both files, and
comm -23 f1 f2
prints lines that are in the first file but not in the second. This is useful for comparing directories. Suppose we have two directories dir1 and dir2 that have many files in common but just a few differences. We are interested in the files that are in dir1 but not in dir2. Here is how to accomplish that.
[amit@onyx comm]: ls dir1 f1 f2 f3 f4 f5 f6 f8 [amit@onyx comm]: ls dir2 f1 f2 f3 f4 f5 f6 f7 f9 [amit@onyx comm]: ls dir1 > dir1.list [amit@onyx comm]: ls dir2 > dir2.list [amit@onyx comm]: comm -23 dir1.list dir2.list f8 [amit@onyx comm]: comm -13 dir1.list dir2.list f7 f9 [amit@onyx comm]: