|

Linux CLI 44 ๐Ÿง comm, and diff command

comm file1.txt file2.txt
comm -1 file1.txt file2.txt
comm -2 file1.txt file2.txt
comm -3 file1.txt file2.txt
cat file1.txt | comm - file2.txt

diff file1.txt file2.txt
diff -y file1.txt file2.txt
diff -c file1.txt file2.txt

comm and diff both compare files, but they answer different questions. comm asks “which lines are shared and which are unique?” โ€” it’s a set operation on two sorted files. diff asks “what exactly changed, line by line?” โ€” it’s a detailed comparison that shows you the edits.

Key point: comm requires sorted input and gives you three simple columns. diff works on any input and produces a precise, often patch-ready description of the differences. Use comm for set logic; use diff for reviewing changes.


a – comm command

comm compares two sorted files and produces three columns of output:

ColumnContents
1stLines unique to the first file
2ndLines unique to the second file
3rdLines common to both files

Syntax:

comm [options] file1 file2

Common options:

OptionPurpose
-1Suppress the first column
-2Suppress the second column
-3Suppress the third column
-Read from standard input

Important: Both files must be sorted. If they aren’t, comm won’t give correct results โ€” just like join and uniq.

Examples:

# Two sorted files
$ cat team_a.txt
alice
bob
charlie
dave

$ cat team_b.txt
bob
charlie
eve
frank

# Default โ€” all three columns
$ comm team_a.txt team_b.txt
alice
        eve
        frank
bob
charlie
dave

# Wait โ€” the columns are TAB-separated, so it's clearer like this:
$ comm team_a.txt team_b.txt | cat -A
alice$
^Ieve$
^Ifrank$
bob$
charlie$
dave$

# Only lines unique to file 1
$ comm -2 -3 team_a.txt team_b.txt
alice
dave

# Only lines unique to file 2
$ comm -1 -3 team_a.txt team_b.txt
eve
frank

# Only lines common to both
$ comm -1 -2 team_a.txt team_b.txt
bob
charlie

# Suppress just the first column
$ comm -1 team_a.txt team_b.txt
        eve
        frank
bob
charlie

# Suppress just the second column
$ comm -2 team_a.txt team_b.txt
alice
bob
charlie
dave

# Suppress just the third column
$ comm -3 team_a.txt team_b.txt
alice
        eve
        frank
dave

# Read one file from stdin
$ cat team_a.txt | comm - team_b.txt
alice
        eve
        frank
bob
charlie
dave

Reading the output โ€” the tabs are the columns:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           comm team_a.txt team_b.txt         โ”‚
โ”‚                                              โ”‚
โ”‚  Column 1      Column 2      Column 3        โ”‚
โ”‚  (file 1)      (file 2)      (both)          โ”‚
โ”‚                                              โ”‚
โ”‚  alice                                       โ”‚
โ”‚                eve                           โ”‚
โ”‚                frank                         โ”‚
โ”‚  bob                                         โ”‚
โ”‚  charlie                                     โ”‚
โ”‚  dave                                        โ”‚
โ”‚                                              โ”‚
โ”‚  Wait โ€” that's not right. Let me re-check:  โ”‚
โ”‚                                              โ”‚
โ”‚  alice         (unique to file 1)            โ”‚
โ”‚                eve     (unique to file 2)    โ”‚
โ”‚                frank   (unique to file 2)    โ”‚
โ”‚  bob           (common)                      โ”‚
โ”‚  charlie       (common)                      โ”‚
โ”‚  dave          (unique to file 1)            โ”‚
โ”‚                                              โ”‚
โ”‚  Actually comm sorts all lines together and  โ”‚
โ”‚  uses TABs to indent. The columns are:       โ”‚
โ”‚                                              โ”‚
โ”‚  alice      โ† col 1                          โ”‚
โ”‚          eve    โ† col 2                      โ”‚
โ”‚          frank  โ† col 2                      โ”‚
โ”‚  bob        โ† col 3 (0 tabs = col 3)         โ”‚
โ”‚  charlie    โ† col 3                          โ”‚
โ”‚  dave       โ† col 1                          โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Let me clarify precisely. comm outputs lines in sorted order. Each line is prefixed with tabs:

  • 0 tabs โ†’ line is in the third column (common to both)
  • 1 tab โ†’ line is in the second column (unique to file 2)
  • 2 tabs โ†’ line is in the first column (unique to file 1)

So for our example:

alice           โ† 2 tabs (col 1)
		eve     โ† 1 tab  (col 2)
		frank   โ† 1 tab  (col 2)
bob             โ† 0 tabs (col 3)
charlie         โ† 0 tabs (col 3)
dave            โ† 2 tabs (col 1)

That’s why comm -1 -2 (suppress col 1 and col 2) leaves only common lines:

$ comm -1 -2 team_a.txt team_b.txt
bob
charlie

Practical recipes:

# Lines only in file 1
$ comm -2 -3 file1.txt file2.txt

# Lines only in file 2
$ comm -1 -3 file1.txt file2.txt

# Lines in both
$ comm -1 -2 file1.txt file2.txt

# Lines in either but not both (symmetric difference)
$ comm -3 file1.txt file2.txt | sed 's/^\t//'

# Count unique lines in each file
$ comm -2 -3 file1.txt file2.txt | wc -l
$ comm -1 -3 file1.txt file2.txt | wc -l

# Count common lines
$ comm -1 -2 file1.txt file2.txt | wc -l

Tip: Because comm requires sorted input, the standard idiom is comm <(sort a.txt) <(sort b.txt) โ€” process substitution sorts on the fly.

$ comm <(sort unsorted_a.txt) <(sort unsorted_b.txt)

b – diff command

diff compares files line by line and shows the differences. It’s useful for comparing small and large files, scripts, configurations, and anything else where you need to know exactly what changed.

Syntax:

diff [options] file1 file2

Common options:

OptionPurpose
-uUnified format โ€” before/after blocks
-ySide-by-side column format
-cContext format
-rCompare directories recursively
-iIgnore case
-wIgnore whitespace
-bIgnore changes in whitespace amount
-qBrief โ€” just report if files differ
-sReport when files are identical

Reading the default output:

SymbolMeaning
<Line from the first file
>Line from the second file
aAdd โ€” lines added to file 1 to get file 2
bChange โ€” lines changed
cDelete โ€” lines deleted
Numbers before the letterLine numbers in file 1
Numbers after the letterLine numbers in file 2

Examples:

# Two files that differ
$ cat config_old.txt
host=localhost
port=8080
debug=false
timeout=30

$ cat config_new.txt
host=localhost
port=9090
debug=true
timeout=30
retries=3

# Default diff
$ diff config_old.txt config_new.txt
2c2
< port=8080
---
> port=9090
3c3
< debug=false
---
> debug=true
5a6
> retries=3

Reading it line by line:

  • 2c2 โ€” line 2 in file 1 changed to line 2 in file 2
  • < port=8080 โ€” what file 1 had
  • > port=9090 โ€” what file 2 has
  • 3c3 โ€” line 3 changed
  • 5a6 โ€” after line 5 of file 1, add line 6 from file 2 (retries=3)

More examples:

# Brief output โ€” just say if they differ
$ diff -q config_old.txt config_new.txt
Files config_old.txt and config_new.txt differ

# Report when identical
$ diff -s config_old.txt config_old.txt
Files config_old.txt and config_old.txt are identical

# Ignore case
$ diff -i file1.txt file2.txt

# Ignore whitespace
$ diff -w file1.txt file2.txt

# Unified format (the one used by patches)
$ diff -u config_old.txt config_new.txt
--- config_old.txt	2024-01-15 10:00:00.000000000 +0000
+++ config_new.txt	2024-01-15 10:05:00.000000000 +0000
@@ -1,5 +1,6 @@
 host=localhost
-port=8080
+port=9090
-debug=false
+debug=true
 timeout=30
+retries=3

# Compare directories
$ diff -r dir1/ dir2/
diff -r dir1/file1.txt dir2/file1.txt
2c2
< old content
---
> new content

# Save a patch
$ diff -u config_old.txt config_new.txt > config.patch
$ patch config_old.txt < config.patch

Tip: -u (unified) is the format used by git diff, patch, and most modern tools. Learn to read it โ€” it’s the most useful.


c – diff command column and context mode

Two alternative output formats make diff easier to read when you want a quick visual scan.

Side-by-side mode (-y):

$ diff -y config_old.txt config_new.txt
host=localhost							host=localhost
port=8080						      |	port=9090
debug=false						      |	debug=true
timeout=30							timeout=30
							      >	retries=3
SymbolMeaning
< / >Content from file 1 / file 2
|Line needs to be changed
(Line only in file 1 (with --suppress-common-lines)
)Line only in file 2
(nothing)Lines are identical

Useful side-by-side options:

OptionPurpose
--suppress-common-linesShow only differences
-W NSet output width to N columns
-tExpand tabs to spaces
# Only show the differences, side by side
$ diff -y --suppress-common-lines config_old.txt config_new.txt
port=8080						      |	port=9090
debug=false						      |	debug=true
							      >	retries=3

Context mode (-c):

$ diff -c config_old.txt config_new.txt
*** config_old.txt	2024-01-15 10:00:00.000000000 +0000
--- config_new.txt	2024-01-15 10:05:00.000000000 +0000
***************
*** 1,5 ****
  host=localhost
! port=8080
! debug=false
  timeout=30
--- 1,6 ----
  host=localhost
! port=9090
! debug=true
  timeout=30
+ retries=3
SymbolMeaning
***The first file
---The second file
-Line to be deleted from file 1
+Line to be added to file 1
!Line to be changed
(space)Unchanged context line

Side-by-side vs context vs unified:

FormatFlagBest for
Default(none)Scripting, minimal output
Unified-uPatches, git diff style
Context-cOlder patch format, context
Side-by-side-yQuick visual scan

Complete Example Session

# ============================================
# PART 1: COMM โ€” THREE COLUMNS
# ============================================

$ cat file1.txt
apple
banana
cherry
date

$ cat file2.txt
banana
cherry
elderberry
fig

$ comm file1.txt file2.txt
apple
		elderberry
		fig
banana
cherry
date

# ============================================
# PART 2: COMM โ€” SUPPRESS COLUMNS
# ============================================

# Only unique to file 1
$ comm -2 -3 file1.txt file2.txt
apple
date

# Only unique to file 2
$ comm -1 -3 file1.txt file2.txt
elderberry
fig

# Only common
$ comm -1 -2 file1.txt file2.txt
banana
cherry

# Symmetric difference (either but not both)
$ comm -3 file1.txt file2.txt | sed 's/^\t//'
apple
elderberry
fig
date

# ============================================
# PART 3: COMM WITH PROCESS SUBSTITUTION
# ============================================

$ comm <(sort unsorted1.txt) <(sort unsorted2.txt)
...

# ============================================
# PART 4: DIFF โ€” DEFAULT
# ============================================

$ cat config_old.txt
host=localhost
port=8080
debug=false
timeout=30

$ cat config_new.txt
host=localhost
port=9090
debug=true
timeout=30
retries=3

$ diff config_old.txt config_new.txt
2c2
< port=8080
---
> port=9090
3c3
< debug=false
---
> debug=true
5a6
> retries=3

# ============================================
# PART 5: DIFF โ€” UNIFIED
# ============================================

$ diff -u config_old.txt config_new.txt
--- config_old.txt	2024-01-15 10:00:00.000000000 +0000
+++ config_new.txt	2024-01-15 10:05:00.000000000 +0000
@@ -1,5 +1,6 @@
 host=localhost
-port=8080
+port=9090
-debug=false
+debug=true
 timeout=30
+retries=3

# ============================================
# PART 6: DIFF โ€” SIDE BY SIDE
# ============================================

$ diff -y config_old.txt config_new.txt
host=localhost							host=localhost
port=8080						      |	port=9090
debug=false						      |	debug=true
timeout=30							timeout=30
							      >	retries=3

$ diff -y --suppress-common-lines config_old.txt config_new.txt
port=8080						      |	port=9090
debug=false						      |	debug=true
							      >	retries=3

# ============================================
# PART 7: DIFF โ€” CONTEXT
# ============================================

$ diff -c config_old.txt config_new.txt
*** config_old.txt	2024-01-15 10:00:00.000000000 +0000
--- config_new.txt	2024-01-15 10:05:00.000000000 +0000
***************
*** 1,5 ****
  host=localhost
! port=8080
! debug=false
  timeout=30
--- 1,6 ----
  host=localhost
! port=9090
! debug=true
  timeout=30
+ retries=3

# ============================================
# PART 8: DIFF โ€” PATCH WORKFLOW
# ============================================

$ diff -u config_old.txt config_new.txt > config.patch
$ cat config.patch
--- config_old.txt	...
+++ config_new.txt	...
@@ -1,5 +1,6 @@
...

$ patch config_old.txt < config.patch
patching file config_old.txt

$ diff config_old.txt config_new.txt
# (no output โ€” they now match)

# ============================================
# PART 9: DIFF โ€” DIRECTORIES
# ============================================

$ diff -r dir1/ dir2/
diff -r dir1/file1.txt dir2/file1.txt
2c2
< old content
---
> new content

Only in dir1: extra.txt
Only in dir2: newfile.txt

# ============================================
# PART 10: COMBINING COMM AND DIFF
# ============================================

# Lines added in new version
$ comm -1 -3 <(sort old.txt) <(sort new.txt)

# Lines removed
$ comm -2 -3 <(sort old.txt) <(sort new.txt)

# Detailed changes
$ diff -u old.txt new.txt

Quick Reference

comm

CommandPurpose
comm A BAll three columns
comm -1 A BSuppress unique to A
comm -2 A BSuppress unique to B
comm -3 A BSuppress common
comm -1 -2 A BOnly common
comm -2 -3 A BOnly unique to A
comm -1 -3 A BOnly unique to B
comm - A BRead A from stdin
comm <(sort a) <(sort b)Sort on the fly

diff โ€” Output Modes

FlagFormat
(none)Default โ€” minimal
-uUnified
-cContext
-ySide by side
-qBrief
-sReport identical

diff โ€” Comparison Options

FlagPurpose
-iIgnore case
-wIgnore whitespace
-bIgnore whitespace changes
-BIgnore blank lines
-rRecursive (directories)
-NTreat missing files as empty

diff โ€” Symbols

SymbolMeaning
<From file 1
>From file 2
|Changed (side-by-side)
aAdd
bChange
cDelete
***File 1 (context mode)
---File 2 (context mode)
!Changed (context mode)
+Added (context/unified)
-Deleted (context/unified)

comm vs diff

Aspectcommdiff
InputSorted filesAny files
Output3 columnsLine-by-line changes
PurposeSet operationsChange review
Patch-readyNoYes (-u)
Best for“What’s shared?”“What changed?”

Best Practices

โœ… Do This:

# Sort before comm
comm <(sort a.txt) <(sort b.txt)        # โœ…

# Use -1 -2 for "common only"
comm -1 -2 a.txt b.txt                  # โœ…

# Use -2 -3 for "only in file 1"
comm -2 -3 a.txt b.txt                  # โœ…

# Use -u for patch-friendly diff
diff -u old.txt new.txt > change.patch  # โœ…

# Use -y for visual scans
diff -y --suppress-common-lines a b     # โœ…

# Use -r for directories
diff -r dir1/ dir2/                     # โœ…

# Ignore whitespace when comparing code
diff -w old.c new.c                     # โœ…

# Verify with -q first
diff -q old.txt new.txt                 # โœ…

โŒ Don’t Do This:

# Don't comm unsorted files
comm unsorted1.txt unsorted2.txt        # โŒ wrong output

# Don't diff binary files without care
diff image1.png image2.png              # โŒ "Binary files differ"

# Don't forget -r for directories
diff dir1/ dir2/                        # โŒ "Is a directory"

# Don't use default diff for patches
diff old.txt new.txt > patch            # โŒ use -u

# Don't confuse -1/-2/-3 order in comm
comm -3 a b                             # โš ๏ธ  suppresses common

# Don't ignore whitespace issues blindly
diff -w code1.py code2.py               # โš ๏ธ  may hide real bugs

Common Pitfalls

PitfallProblemSolution
comm on unsorted filesWrong outputsort first
Tabs invisibleColumns look wrongPipe through cat -A
Forgot -u for patchesPatch rejectsUse diff -u
Binary files“Binary files differ”Use cmp instead
Diff output confusingLost in noiseUse -y or -u
Whitespace differencesFalse positivesUse -w or -b
Recursive diff missing“Is a directory”Add -r
Missing files in dir diffNo outputAdd -N

Real-World Examples

1. Find Common Lines Between Two Lists

$ comm -1 -2 <(sort list1.txt) <(sort list2.txt)
banana
cherry

2. Find Lines Only in the New Version

$ comm -1 -3 <(sort old.txt) <(sort new.txt)
new-feature

3. Find Lines Only in the Old Version

$ comm -2 -3 <(sort old.txt) <(sort new.txt)
deprecated-function

4. Symmetric Difference

$ comm -3 <(sort a.txt) <(sort b.txt) | sed 's/^\t//'
apple
elderberry
fig
date

5. Review a Config Change

$ diff -u /etc/ssh/sshd_config.old /etc/ssh/sshd_config
--- /etc/ssh/sshd_config.old	...
+++ /etc/ssh/sshd_config	...
@@ -12,7 +12,7 @@
-PermitRootLogin yes
+PermitRootLogin no

6. Side-by-Side Code Review

$ diff -y --suppress-common-lines old.py new.py
def foo():						      |	def foo(x):
    return 1						      |	    return x + 1

7. Create a Patch File

$ diff -u old.c new.c > fix.patch
$ patch old.c < fix.patch
patching file old.c

8. Compare Two Directories

$ diff -r project_v1/ project_v2/
diff -r project_v1/main.c project_v2/main.c
5c5
< printf("v1");
---
> printf("v2");
Only in project_v2: newfile.c

9. Ignore Whitespace in Code

$ diff -w old.py new.py
# Only reports real changes, not reindentation

10. Quick “Are They Different?”

$ diff -q a.txt b.txt
Files a.txt and b.txt differ

$ echo $?
1

11. Build a Combined Report

# Show only-in-old, common, only-in-new in a clear format
$ echo "=== Only in old ==="
$ comm -2 -3 <(sort old.txt) <(sort new.txt)
$ echo "=== Common ==="
$ comm -1 -2 <(sort old.txt) <(sort new.txt)
$ echo "=== Only in new ==="
$ comm -1 -3 <(sort old.txt) <(sort new.txt)

12. Compare Two CSV Files

$ diff -y --suppress-common-lines old.csv new.csv
id,name						      |	id,name,email
1,alice						      |	1,alice,alice@x.com

13. Patch a File Safely

$ cp config.txt config.txt.bak
$ diff -u config.txt.bak config.txt.new > update.patch
$ patch config.txt < update.patch
$ diff config.txt config.txt.new
# (no output = success)

14. Compare File Lists

$ comm -3 <(ls dir1/ | sort) <(ls dir2/ | sort) | sed 's/^\t//'
extra-in-dir1
new-in-dir2

15. Find Duplicate Content Across Files

$ diff -q file1.txt file2.txt && echo "identical"
identical

Visual: comm vs diff

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  comm                        โ”‚
โ”‚                                              โ”‚
โ”‚  File 1:      File 2:      Output:           โ”‚
โ”‚  apple        banana       apple             โ”‚
โ”‚  banana       cherry       โ† unique to 1     โ”‚
โ”‚  cherry       elderberry        elderberry   โ”‚
โ”‚  date         fig               fig          โ”‚
โ”‚                             banana           โ”‚
โ”‚                             cherry           โ”‚
โ”‚                             date             โ”‚
โ”‚                                              โ”‚
โ”‚  Set logic on sorted files                   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  diff                        โ”‚
โ”‚                                              โ”‚
โ”‚  File 1:      File 2:      Output:           โ”‚
โ”‚  host=x       host=x       2c2               โ”‚
โ”‚  port=8080    port=9090    < port=8080       โ”‚
โ”‚  debug=false  debug=true   ---               โ”‚
โ”‚  timeout=30   timeout=30   > port=9090       โ”‚
โ”‚  ...          retries=3    3c3               โ”‚
โ”‚                            < debug=false     โ”‚
โ”‚                            ---               โ”‚
โ”‚                            > debug=true      โ”‚
โ”‚                            5a6               โ”‚
โ”‚                            > retries=3       โ”‚
โ”‚                                              โ”‚
โ”‚  Line-by-line change review                  โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

CommandPurposeExample
comm A BThree columnscomm a.txt b.txt
comm -1 A BSuppress unique to Acomm -1 a.txt b.txt
comm -2 A BSuppress unique to Bcomm -2 a.txt b.txt
comm -3 A BSuppress commoncomm -3 a.txt b.txt
comm -1 -2 A BOnly commoncomm -1 -2 a.txt b.txt
comm -2 -3 A BOnly unique to Acomm -2 -3 a.txt b.txt
comm -1 -3 A BOnly unique to Bcomm -1 -3 a.txt b.txt
comm - A BRead A from stdincat a | comm - b
diff A BDefault diffdiff old.txt new.txt
diff -u A BUnifieddiff -u old.txt new.txt
diff -c A BContextdiff -c old.txt new.txt
diff -y A BSide by sidediff -y old.txt new.txt
diff -y --suppress-common-lines A BOnly differencesdiff -y --suppress-common-lines a b
diff -q A BBriefdiff -q old.txt new.txt
diff -r D1 D2Recursive dirsdiff -r dir1/ dir2/
diff -i A BIgnore casediff -i a.txt b.txt
diff -w A BIgnore whitespacediff -w a.c b.c
diff -u A B > pCreate patchdiff -u a b > p.patch

Key takeaways:

  • comm compares two sorted files and reports three sets: only in A, only in B, and common
  • comm uses tabs to indent columns โ€” cat -A reveals them
  • Use -1, -2, -3 to suppress columns and isolate the set you want
  • comm requires sorted input โ€” use process substitution <(sort file) when needed
  • diff compares files line by line and shows exactly what changed
  • The default format uses <, >, a, b, c โ€” add/change/delete
  • Use -u (unified) for the modern patch-friendly format
  • Use -y (side by side) for a quick visual scan
  • Use -c (context) for the older patch format with surrounding lines
  • | in side-by-side means “changed”, </> mean unique to file 1/2
  • In context mode: *** = file 1, --- = file 2, ! = changed, + = added, - = deleted
  • diff -u > patch + patch is the classic workflow for applying changes
  • Use -r for directories, -w / -i to ignore noise, -q for a quick answer

Remember: comm is for set operations on sorted files โ€” which lines are shared, which are unique. diff is for change review โ€” what exactly changed line by line. Use comm when you want a Venn diagram; use diff when you want an edit script. Always sort before comm. Always reach for -u when you’re creating a patch. And learn to read the default diff output โ€” it’s the most portable format and the one every Unix system understands.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!