The output is actually a description of how to transform the old file into the new one. Here, diff is telling you three things:
· !SPAN>The fifth line of the file has undergone a change. The 5c5 message says to replace line 5 of the old file with line 5 of the new file. Both the old and new text are displayed, separated by a line of three dashes. (The less-than (<) notation means "remove this line," and the greater-than (>) sign means "add this line.")
· !SPAN>Line 7 of the old file does not appear in the new file. The 7d6 message says to delete line 7 from the old file, and the files will then be in sync, starting at line 6 of the new file. The text to be deleted is displayed on the next line.
· !SPAN>A line was added to the new file. The 21a22 message says to add a new line after line 21 of the old file. The text to be added is displayed on the final line of the output.
Two useful flags you can specify when comparing files are !SPAN>-b (ignore blanks) and !SPAN>-i (ignore case). You can use them separately or in combination. The ignore blanks feature is especially useful when you're comparing the source code for two programs, since indentation changes are rarely significant. For example, here's how you might compare two program files, !SPAN>ur2cool.c and !SPAN>ur2cool.backup:!SPAN>
diff -b -i ur2cool.c ur2cool.backup!SPAN>
Don't worry if you have some difficulty understanding the output of the !SPAN>diff command. It's c ryptic because it was designed to be used by computers, not humans. (Some source-code control systems used by programmers use !SPAN>diff to keep a record of the changes made to a program over time.)!SPAN>
Do pay attention, though, to the less-than and greater-than indicators to see at a glance what was added or deleted; and be happy if you manage to get a general feeling for the ways the files differ.!SPAN>
For more information on the diff command, see the diff manual.
Previous Lesson: Searching for Files
Next Lesson: Task Scheduling
Comments (most recent first)
linux beginner (06 Aug 2010, 04:43)
Can I use diff or cmp command to compare two pdf files or doc files?
Anes (05 Jul 2010, 09:31)
Hi Akshada ,
The difference b/w cmp and diff is: The cmp command is a simpler version of diff, above. Whereas diff reports the differences between two files, cmp merely shows at what point they differ. if you need any clarification , contact me at anes.pa at gmail.com bye anes
larry (23 Jun 2010, 14:33)
Thanks for explaining a tough to understand topic in a very simple and easy
to understand manner.
Akshada (17 Jun 2010, 11:22)
Can we use "cmp" command instead of "diff" ?
What is the difference between both ?
vaidyanathan (07 Jun 2010, 02:49)
Thanks A lot Bob... one of the few newser-friendly pages on the net..:)
Kevin (27 May 2010, 04:00)
Took me ages to find someone who just EXPLAINED WHAT THE OUTPUT MEANT.
Thanks.
Mohanraj (28 Apr 2010, 22:24)
Really a very good explaination. Thanks!
Pankaj (19 Apr 2010, 04:35)
nice explanation
Bob Rankin (13 Mar 2010, 08:39)
The 5c5/7d6, etc. shown above is just a sample of the output from the diff
command.
Test (12 Mar 2010, 04:15)
Which flag can help me get rid of 5c5 / 7d6 / 21a22. i using linux
SaefUllah (22 Feb 2010, 11:08)
Thanks for making things easy for me
Esteban Talavera (10 Feb 2010, 09:30)
Thanks!
|
|
|
![]() |
|
| <Send This Link to a Friend> <Bookmark This Page> | ||