home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


diff

diff [options ] [diroptions ] file1 file2

diff reports lines that differ between file1 and file2 . Output consists of lines of context from each file, with file1 text flagged by a < symbol and file2 text by a > symbol. Context lines are preceded by the ed command (a , c , or d ) that converts file1 to file2 . If one of the files is - , standard input is read. If one of the files is a directory, diff locates the filename in that directory corresponding to the other argument (e.g., diff my_dir junk is the same as diff my_dir/junk junk ). If both arguments are directories, diff reports lines that differ between all pairs of files having equivalent names (e.g., olddir/program and newdir/program ); in addition, diff lists filenames unique to one directory, as well as subdirectories common to both. See also bdiff , cmp , comm , diff3 , dircmp , and sdiff .

Options

Options -c , -C , -D , -e , -f , -h , and -n cannot be combined with each other (they are mutually exclusive).

-b

Ignore repeating blanks and end-of-line blanks; treat successive blanks as one.

-c

Produce output in alternate format, with three lines of context. (This is called a "context diff.")

-C n

Like -c , but produce n lines of context.

-D def

Merge file1 and file2 into a single file containing conditional C preprocessor directives (#ifdef ). Defining def and then compiling yields file2 ; compiling without defining def yields file1 .

-e

Produce a script of commands (a , c , d ) to recreate file2 from file1 using the ed editor.

-f

Produce a script to recreate file1 from file2 ; the script is in the opposite order, so it isn't useful to ed .

-h

Do a half-hearted (but hopefully faster) comparison; complex differences (e.g., long stretches of many changes) may not show up; -e and -f are disabled.

-i

Ignore uppercase and lowercase distinctions.

-n

Like -f , but counts changed lines. rcsdiff works this way.

-t

Expand tabs in output lines; useful for preserving indentation changed by -c format.

-w

Like -b , but ignores all spaces and tabs; e.g., a + b is the same as a+b .

The following diroptions are valid only when both file arguments are directories.

Diroptions

-l

Long format; output is paginated by pr so that diff listings for each file begin on a new page; other comparisons are listed afterward.

-r

Run diff recursively for files in common subdirectories.

-s

Report files that are identical.

-S file

Begin directory comparisons with file , skipping files whose names alphabetically precede file .


Previous: Reference: df UNIX in a Nutshell: System V Edition Next: Reference: diff3
Reference: df Book Index Reference: diff3

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System