The diff command is a standard Linux utility used to compare the contents of two files line by line. It highlights the differences between them, making it useful for tasks like code review, version control, and configuration management.
Basic Usage
To use the diff command, you can run:
diff file1.txt file2.txt
Output Explanation
The output format typically includes:
- Lines that differ are prefixed with
<(from the first file) and>(from the second file). - The output may also show line numbers and change indicators (e.g.,
cfor change,dfor delete,afor add).
Example Output
For example, if you compare two files:
1c1
< The quick brown fox jumps over the lazy dog
---
> The quick brown lynx jumps over the lazy dog
This means:
- Line 1 in
file1.txtneeds to be changed to match line 1 infile2.txt.
Useful Options
-
Side-by-side comparison:
diff -y file1.txt file2.txt -
Unified format (common in patches):
diff -u file1.txt file2.txt
The diff command is powerful for quickly identifying changes between files. If you have more specific questions or need examples, let me know!
