01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CH07.fm Page 216 Monday, October 7, 2002 9:12 PM<br />

216 Chapter 7 • Miscellaneous Tools<br />

what changes have been made in the working copy of the file. <strong>The</strong> output of the diff utility follows<br />

similar rules to those used in the CVS diff comm<strong>and</strong>. <strong>The</strong> following comm<strong>and</strong> shows<br />

that files hello.c <strong>and</strong> hello.c~ are different at line number 11. <strong>The</strong> line starting with the<br />

less-than symbol is taken from the first file (hello.c) <strong>and</strong> the line starting with the greaterthan<br />

symbol is taken from the file hello.c~.<br />

[root@boota]# diff hello.c hello.c~<br />

11c11<br />

< char string[30];<br />

---<br />

> char string[25];<br />

[root@boota]#<br />

<strong>The</strong> first line of the output contains the character c (changed) that shows that line 11 in the<br />

first file is changed to line 11 in the second file.<br />

You can also use “unified diff” that tells you additional information about the file<br />

<strong>and</strong> displays a few lines before <strong>and</strong> after the lines that are different. See the following output of<br />

the unified diff comm<strong>and</strong>:<br />

[root@boota]# diff hello.c hello.c~ -u<br />

--- hello.cTue Jun 25 14:43:30 2002<br />

+++ hello.c~Tue Jun 25 14:43:38 2002<br />

@@ -8,7 +8,7 @@<br />

main ()<br />

{<br />

- char string[30];<br />

+ char string[25];<br />

printf ("Enter a line of characters : ");<br />

scanf ("%s", string);<br />

[root@boota]#<br />

You can also use the –p option with the comm<strong>and</strong> to display the name of the function in<br />

which the modified line(s) exist.<br />

If you add a line after line 15 in hello.c file <strong>and</strong> run the diff comm<strong>and</strong> once again,<br />

the result will be as follows:<br />

[root@boota]# diff hello.c hello.c~<br />

11c11<br />

< char string[30];<br />

---<br />

> char string[25];<br />

16d15<br />

< printf ("End of program\n");<br />

[root@boota]#

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!