Computer Hope

Other Pages

Home
Site map
Computer help

Dictionary
News
Q&A
What's new

Tools

E-mail this page
Print Preview
Edit this page



 

Linux / Unix diff command

Quick links

About diff
Syntax
Examples
Related commands
Linux / Unix main page

About diff

Displays two files and prints the lines that are different.

Syntax

diff [-b] [-i] [-t] [-w] [-c] [-C] [-e] [-f] [-h] [-n] [-D string] [-l] [-r] [-s] [-S name] [fileone filetwo ] [directoryone directorytwo]

-b Ignores spacing differences.
-i Ignores case.
-t Expands TAB characters in output lines. Normal or -c output adds character(s) to the front of each  line that may adversely affect the indentation of the original source lines and make the output lines difficult to interpret. This option will preserve the original source's indentation.
-w Ignores spaces and tabs.
-c Produces a listing of differences with three lines of context. With this option output format is modified slightly: output begins with identification of the files involved and their creation dates, then each change is separated by a line with a dozen *'s. The lines removed from file1 are marked with '-'; those added to file2 are marked '+'. Lines that are changed from one file to the other are marked in both files with '!'.
-C Produces a listing of differences identical to that produced by -c with number lines of context.
-e Produces a script of only a, c, and d commands for the editor ed , which will recreate file2 from file1. In connection with -e, the following shell program may help maintain multiple versions of a file. Only an ancestral file ($1) and a chain of version-to-version ed scripts ($2,$3,...) made by diff need be on hand. A ``latest version'' appears on the standard output. 

(shift; cat $*; echo '1,$p') | ed - $1

-f Produces a similar script, not useful with ed , in the opposite order.
-h Does a fast, half-hearted job. It works only when changed stretches are short and well separated, but does work on files of unlimited length.  Options -c, -e, -f, and -n are unavailable with -h. diff does not descend into directories with this option.
-n Produces a script similar to -e, but in the opposite order and with a count of changed  lines on each insert or delete command.
-D string Creates a merged version of file1 and file2 with C preprocessor controls included so that a compilation of the result without defining string is equivalent to compiling file1, while defining string will yield file2.
-l Produce output in long format. Before the diff, each text file is piped through pr(1) to paginate it. Other differences are remembered and summarized after all text file differences are reported.
-r Applies diff recursively to common subdirectories encountered.
-s Reports files that are the identical; these would not otherwise be mentioned.
-S name Starts a directory diff in the middle, beginning with the file name.
filenameone File one for comparing.
filenametwo File two for comparing.
directoryone Directory one for comparing.
directorytwo Directory two for comparing.

Examples

diff help dir2 - Compares the directory named help with the directory named dir2. Below is an example of the output when typing this command.

Only in help: tab2.gif
Only in help: tab3.gif
Only in help: tab4.gif
Only in help: tape.htm
Only in help: tbernoul.htm
Only in help: tconner.htm
Only in help: tempbus.psd

Related commands

bdiff
cmp
comm
dircmp
ed
pr
ls
sdiff

 

Index

Category:
Linux / Unix

Companies:
Click here

Related Pages:

Resolved

Were you able to locate the answer to your questions?

Home - Computer help - Contact - Dictionary - Links
Link to Computer Hope - Bookmark Computer Hope