1.8 Comparing Files While They Are Changing

Commands like diff read files and directories by using a series of system calls, as operating systems typically do not give a program a way to snapshot all its input before processing it. If input files change while being read, diff and related commands can generate output that does not correspond to any state of the input file system.

For example, if some other process truncates a file to zero size when diff has read just half the file, diff will use the half that it read as its input data. As another example, if a recursive diff determines that a file is a directory, and then some other process replaces the directory with a regular file, and then diff attempts to descend into the directory, diff will issue a diagnostic and fail.

In these situations the output of diff and related programs should be interpreted with some care.