diff Linux Commands
What is Linux diff Command?
Explanation
diff COMMAND:diff command is used to find differences between two files.
SYNTAX :
diff [options..] from-file to-file
OPTIONS:
| -a |
Treat all files as text and compare them line-by-line. |
| -b |
Ignore changes in amount of white space. |
| -c |
Use the context output format. |
| -e |
Make output that is a valid ed script. |
| -H |
Use heuristics to speed handling of large files that have numerous scattered small changes. |
| -i |
Ignore changes in case; consider upper- and lower-case letters equivalent. |
| -n |
Prints in RCS-format, like -f except that each command specifies the number of lines affected. |
| -q |
Output RCS-format diffs; like -f except that each command specifies the number of lines affected.
|
| -r |
When comparing directories, recursively compare any subdirectories found. |
| -s |
Report when two files are the same. |
| -w |
Ignore white space when comparing lines. |
| -y |
Use the side by side output format. |
EXAMPLE:
Lets create two files file1.txt and file2.txt and let it have the following data.
| Data in file1.txt |
Data in file2.txt |
HIOX TEST hscripts.com with friend ship hiox india
|
HIOX TEST HSCRIPTS.com withfriend ship |
- Compare files ignoring white space:
diff-wfile1.txtfile2.txt
This command will compare the file file1.txt with file2.txt ignoring white/blank space and
it will produce the following output.
2c2
< hscripts.com
---
> HSCRIPTS.com
4d3
< Hioxindia.com
- Compare the files side by side, ignoring white space:
diff-byfile1.txtfile2.txt
This command will compare the files ignoring white/blank space, It is easier to differentiate the files.
HIOX TEST
HIOX TEST
hscripts.com
| HSCRIPTS.com
with friend ship
with
friend ship
Hioxindia.com
<
The third line(with friend ship) in file2.txt has more blank spaces, but still the -b ignores the blank space
and does not show changes in the particular line, -y printout the result side by side.
- Compare the files ignoring case.
diff-iyfile1.txtfile2.txt
This command will compare the files ignoring case(upper-case and lower-case) and displays the following output.
HIOX TEST
HIOX TEST
hscripts.com
HSCRIPTS.com
with friend ship
| with
friend ship
Hioxindia.com
<