What is the -Naur in diff program? What is the -Naur in diff program? linux linux

What is the -Naur in diff program?


I realize this is an old question that already has an answer, but it did not go into the depth I was personally looking for. So I did my own research which I am posting below:

I was wondering what is this -Naur switch.

This official GNU site on creating patches site explains it quite well; -Naur is a series of four (4) diff command switches that break down as follows:

  • -N: Treat absent files as empty; Allows the patch create and remove files.
  • -a: Treat all files as text; Allows the patch update non-text (aka: binary) files.
  • -u: Set the default 3 lines of unified context; This generates useful time stamps and context.
  • -r: Recursively compare any subdirectories found; Allows the patch to update subdirectories.

The -u flag confused me a but, but the Wikipedia page on the diff utility has a nice explanation; bold emphasis is mine:

The unified format (or unidiff) inherits the technical improvements made by the context format, but produces a smaller diff with old and new text presented immediately adjacent. Unified format is usually invoked using the "-u" command line option. This output is often used as input to the patch program. Many projects specifically request that "diffs" be submitted in the unified format, making unified diff format the most common format for exchange between software developers.

Unified context diffs were originally developed by Wayne Davison in August 1990 (in unidiff which appeared in Volume 14 of comp.sources.misc). Richard Stallman added unified diff support to the GNU Project's diff utility one month later, and the feature debuted in GNU diff 1.15, released in January 1991. GNU diff has since generalized the context format to allow arbitrary formatting of diffs.

The format starts with the same two-line header as the context format, except that the original file is preceded by "---" and the new file is preceded by "+++". Following this are one or more change hunks that contain the line differences in the file. The unchanged, contextual lines are preceded by a space character, addition lines are preceded by a plus sign, and deletion lines are preceded by a minus sign.

Which all basically means the -u flag allows diff to output patch data in a commonly known, recognized and accepted format.


diff -Naur is an abbreviation for diff -N -a -u -r. You could also write diff -uraN and get the same result. With this information, you can look up the rest in the man page.