Contents|Index|Previous|Next

Invoking diff

diff options ...from-file to-file is the format for running the diff command.

In the simplest case, diff compares the contents of the two files from-file and to-file. A file name of '-' stands for text read from the standard input. As a special case, 'diff - -' compares a copy of standard input to itself. If from-file is a directory and to-file is not, diff compares the file in from-file whose file name is that of to-file, and vice versa. The non-directory file must not be '-'. If both from-file and to-file are directories, diff compares corresponding files in both directories, in alphabetical order; this comparison is not recursive unless the '-r' or '--recursive' option is given. diff never compares the actual contents of a directory as if it were a file. The file that is fully specified may not be standard input, because standard input is nameless and the notion of "file with the same name" does not apply.

diff options begin with '-', so normally from-file and to-file may not begin with '-'. However, '--' as an argument by itself treats the remaining arguments as file names even if they begin with '-'.

An exit status of 0 means no differences were found, 1 means some differences were found, and 2 means trouble. See also Options to diff.