216Chapter7 • Miscellaneous Tools
what changes have been made in the working copy of the file. The output of the
diff
utility fol-
lows similar rules to those used in the CVS
diff
command. The following command shows
that files
hello.c
and
hello.c~
are different at line number 11. The line starting with the
less-than symbol is taken from the first file (
hello.c
) and the line starting with the greater-
than symbol is taken from the file
hello.c~
.
[root@boota]# diff hello.c hello.c~
11c11
< char string[30];
---
> char string[25];
[root@boota]#
The first line of the output contains the character c (changed) that shows that line 11 in the
first file is changed to line 11 in the second file.
You can also use “
unified diff
” that tells you additional information about the file
and displays a few lines before and after the lines that are different. See the following output of
the
unified diff
command:
[root@boota]# diff hello.c hello.c~ -u
--- hello.cTue Jun 25 14:43:30 2002
+++ hello.c~Tue Jun 25 14:43:38 2002
@@ -8,7 +8,7 @@
main ()
{
- char string[30];
+ char string[25];
printf ("Enter a line of characters : ");
scanf ("%s", string);
[root@
boota
]#
You can also use the –
p
option with the command to display the name of the function in
which the modified line(s) exist.
If you add a line after line 15 in
hello.c
file and run the
diff
command once again,
the result will be as follows:
[root@boota]# diff hello.c hello.c~
11c11
< char string[30];
---
> char string[25];
16d15
< printf ("End of program\n");
[root@boota]#
Next Page >>
<< Previous Page
Back to the Table of Contents