logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

diff.1p (24961B)


  1. '\" et
  2. .TH DIFF "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. diff
  12. \(em compare two files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. diff \fB[\fR-c|-e|-f|-u|-C \fIn\fR|-U \fIn\fB] [\fR-br\fB] \fIfile1 file2\fR
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR diff
  21. utility shall compare the contents of
  22. .IR file1
  23. and
  24. .IR file2
  25. and write to standard output a list of changes necessary to convert
  26. .IR file1
  27. into
  28. .IR file2 .
  29. This list should be minimal. No output shall be produced if the files
  30. are identical.
  31. .SH OPTIONS
  32. The
  33. .IR diff
  34. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  35. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  36. .P
  37. The following options shall be supported:
  38. .IP "\fB\-b\fP" 10
  39. Cause any amount of white space at the end of a line to be treated as a
  40. single
  41. <newline>
  42. (that is, the white-space characters preceding the
  43. <newline>
  44. are ignored) and other strings of white-space characters, not including
  45. <newline>
  46. characters, to compare equal.
  47. .IP "\fB\-c\fP" 10
  48. Produce output in a form that provides three lines of copied context.
  49. .IP "\fB\-C\ \fIn\fR" 10
  50. Produce output in a form that provides
  51. .IR n
  52. lines of copied context (where
  53. .IR n
  54. shall be interpreted as a positive decimal integer).
  55. .IP "\fB\-e\fP" 10
  56. Produce output in a form suitable as input for the
  57. .IR ed
  58. utility, which can then be used to convert
  59. .IR file1
  60. into
  61. .IR file2 .
  62. .IP "\fB\-f\fP" 10
  63. Produce output in an alternative form, similar in format to
  64. .BR \-e ,
  65. but not intended to be suitable as input for the
  66. .IR ed
  67. utility, and in the opposite order.
  68. .IP "\fB\-r\fP" 10
  69. Apply
  70. .IR diff
  71. recursively to files and directories of the same name when
  72. .IR file1
  73. and
  74. .IR file2
  75. are both directories.
  76. .RS 10
  77. .P
  78. The
  79. .IR diff
  80. utility shall detect infinite loops; that is, entering a previously
  81. visited directory that is an ancestor of the last file encountered.
  82. When it detects an infinite loop,
  83. .IR diff
  84. shall write a diagnostic message to standard error and shall either
  85. recover its position in the hierarchy or terminate.
  86. .RE
  87. .IP "\fB\-u\fP" 10
  88. Produce output in a form that provides three lines of unified context.
  89. .IP "\fB\-U\ \fIn\fR" 10
  90. Produce output in a form that provides
  91. .IR n
  92. lines of unified context (where
  93. .IR n
  94. shall be interpreted as a non-negative decimal integer).
  95. .SH OPERANDS
  96. The following operands shall be supported:
  97. .IP "\fIfile1\fR,\ \fIfile2\fR" 10
  98. A pathname of a file to be compared. If either the
  99. .IR file1
  100. or
  101. .IR file2
  102. operand is
  103. .BR '\-' ,
  104. the standard input shall be used in its place.
  105. .P
  106. If both
  107. .IR file1
  108. and
  109. .IR file2
  110. are directories,
  111. .IR diff
  112. shall not compare block special files, character special files, or FIFO
  113. special files to any files and shall not compare regular files to
  114. directories.
  115. Further details are as specified in
  116. .IR "Diff Directory Comparison Format".
  117. The behavior of
  118. .IR diff
  119. on other file types is implementation-defined when found in directories.
  120. .P
  121. If only one of
  122. .IR file1
  123. and
  124. .IR file2
  125. is a directory,
  126. .IR diff
  127. shall be applied to the non-directory file and the file contained in
  128. the directory file with a filename that is the same as the last
  129. component of the non-directory file.
  130. .SH STDIN
  131. The standard input shall be used only if one of the
  132. .IR file1
  133. or
  134. .IR file2
  135. operands references standard input. See the INPUT FILES section.
  136. .SH "INPUT FILES"
  137. The input files may be of any type.
  138. .SH "ENVIRONMENT VARIABLES"
  139. The following environment variables shall affect the execution of
  140. .IR diff :
  141. .IP "\fILANG\fP" 10
  142. Provide a default value for the internationalization variables that are
  143. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  144. .IR "Section 8.2" ", " "Internationalization Variables"
  145. for the precedence of internationalization variables used to determine
  146. the values of locale categories.)
  147. .IP "\fILC_ALL\fP" 10
  148. If set to a non-empty string value, override the values of all the
  149. other internationalization variables.
  150. .IP "\fILC_CTYPE\fP" 10
  151. Determine the locale for the interpretation of sequences of bytes of
  152. text data as characters (for example, single-byte as opposed to
  153. multi-byte characters in arguments and input files).
  154. .IP "\fILC_MESSAGES\fP" 10
  155. .br
  156. Determine the locale that should be used to affect the format and
  157. contents of diagnostic messages written to standard error and
  158. informative messages written to standard output.
  159. .IP "\fILC_TIME\fP" 10
  160. Determine the locale for affecting the format of file timestamps
  161. written with the
  162. .BR \-C
  163. and
  164. .BR \-c
  165. options.
  166. .IP "\fINLSPATH\fP" 10
  167. Determine the location of message catalogs for the processing of
  168. .IR LC_MESSAGES .
  169. .IP "\fITZ\fP" 10
  170. Determine the timezone used for calculating file timestamps written
  171. with a context format. If
  172. .IR TZ
  173. is unset or null, an unspecified default timezone shall be used.
  174. .SH "ASYNCHRONOUS EVENTS"
  175. Default.
  176. .SH STDOUT
  177. .SS "Diff Directory Comparison Format"
  178. .P
  179. If both
  180. .IR file1
  181. and
  182. .IR file2
  183. are directories, the following output formats shall be used.
  184. .P
  185. In the POSIX locale, each file that is present in only one directory
  186. shall be reported using the following format:
  187. .sp
  188. .RS 4
  189. .nf
  190. "Only in %s: %s\en", <\fIdirectory pathname\fP>, <\fIfilename\fR>
  191. .fi
  192. .P
  193. .RE
  194. .P
  195. In the POSIX locale, subdirectories that are common to the two
  196. directories may be reported with the following format:
  197. .sp
  198. .RS 4
  199. .nf
  200. "Common subdirectories: %s and %s\en", <\fIdirectory1 pathname\fR>,
  201. <\fIdirectory2 pathname\fR>
  202. .fi
  203. .P
  204. .RE
  205. .P
  206. For each file common to the two directories, if the two files are not to
  207. be compared: if the two files have the same device ID and file
  208. serial number, or are both block special files that refer to the
  209. same device, or are both character special files that refer to the
  210. same device, in the POSIX locale the output format is unspecified.
  211. Otherwise, in the POSIX locale an unspecified format shall be used
  212. that contains the pathnames of the two files.
  213. .P
  214. For each file common to the two directories, if the files are
  215. compared and are identical, no output shall be written. If the two
  216. files differ, the following format is written:
  217. .sp
  218. .RS 4
  219. .nf
  220. "diff %s %s %s\en", <\fIdiff_options\fR>, <\fIfilename1\fR>, <\fIfilename2\fR>
  221. .fi
  222. .P
  223. .RE
  224. .P
  225. where <\fIdiff_options\fP> are the options as specified on the command
  226. line.
  227. .P
  228. All directory pathnames listed in this section shall be relative to the
  229. original command line arguments. All other names of files listed in
  230. this section shall be filenames (pathname components).
  231. .SS "Diff Binary Output Format"
  232. .P
  233. In the POSIX locale, if one or both of the files being compared are not
  234. text files, it is implementation-defined whether
  235. .IR diff
  236. uses the binary file output format or the other formats as specified
  237. below. The binary file output format shall contain the pathnames of
  238. two files being compared and the string
  239. .BR \(dqdiffer\(dq .
  240. .P
  241. If both files being compared are text files, depending on the options
  242. specified, one of the following formats shall be used to write the
  243. differences.
  244. .SS "Diff Default Output Format"
  245. .P
  246. The default (without
  247. .BR \-e ,
  248. .BR \-f ,
  249. .BR \-c ,
  250. .BR \-C ,
  251. .BR \-u ,
  252. or
  253. .BR \-U
  254. options)
  255. .IR diff
  256. utility output shall contain lines of these forms:
  257. .sp
  258. .RS 4
  259. .nf
  260. "%da%d\en", <\fInum1\fR>, <\fInum2\fR>
  261. .P
  262. "%da%d,%d\en", <\fInum1\fR>, <\fInum2\fR>, <\fInum3\fR>
  263. .P
  264. "%dd%d\en", <\fInum1\fR>, <\fInum2\fR>
  265. .P
  266. "%d,%dd%d\en", <\fInum1\fR>, <\fInum2\fR>, <\fInum3\fR>
  267. .P
  268. "%dc%d\en", <\fInum1\fR>, <\fInum2\fR>
  269. .P
  270. "%d,%dc%d\en", <\fInum1\fR>, <\fInum2\fR>, <\fInum3\fR>
  271. .P
  272. "%dc%d,%d\en", <\fInum1\fR>, <\fInum2\fR>, <\fInum3\fR>
  273. .P
  274. "%d,%dc%d,%d\en", <\fInum1\fR>, <\fInum2\fR>, <\fInum3\fR>, <\fInum4\fR>
  275. .fi
  276. .P
  277. .RE
  278. .P
  279. These lines resemble
  280. .IR ed
  281. subcommands to convert
  282. .IR file1
  283. into
  284. .IR file2 .
  285. The line numbers before the action letters shall pertain to
  286. .IR file1 ;
  287. those after shall pertain to
  288. .IR file2 .
  289. Thus, by exchanging
  290. .IR a
  291. for
  292. .IR d
  293. and reading the line in reverse order, one can also determine how to
  294. convert
  295. .IR file2
  296. into
  297. .IR file1 .
  298. As in
  299. .IR ed ,
  300. identical pairs (where
  301. .IR num1 =
  302. .IR num2 )
  303. are abbreviated as a single number.
  304. .P
  305. Following each of these lines,
  306. .IR diff
  307. shall write to standard output all lines affected in the first
  308. file using the format:
  309. .sp
  310. .RS 4
  311. .nf
  312. "< %s", <\fIline\fR>
  313. .fi
  314. .P
  315. .RE
  316. .P
  317. and all lines affected in the second file using the format:
  318. .sp
  319. .RS 4
  320. .nf
  321. "> %s", <\fIline\fR>
  322. .fi
  323. .P
  324. .RE
  325. .P
  326. If there are lines affected in both
  327. .IR file1
  328. and
  329. .IR file2
  330. (as with the
  331. .BR c
  332. subcommand), the changes are separated with a line consisting of three
  333. <hyphen-minus>
  334. characters:
  335. .sp
  336. .RS 4
  337. .nf
  338. "---\en"
  339. .fi
  340. .P
  341. .RE
  342. .SS "Diff \-e Output Format"
  343. .P
  344. With the
  345. .BR \-e
  346. option, a script shall be produced that shall, when provided as input
  347. to
  348. .IR ed ,
  349. along with an appended
  350. .BR w
  351. (write) command, convert
  352. .IR file1
  353. into
  354. .IR file2 .
  355. Only the
  356. .BR a
  357. (append),
  358. .BR c
  359. (change),
  360. .BR d
  361. (delete),
  362. .BR i
  363. (insert), and
  364. .BR s
  365. (substitute) commands of
  366. .IR ed
  367. shall be used in this script. Text lines, except those consisting of
  368. the single character
  369. <period>
  370. (\c
  371. .BR '.' ),
  372. shall be output as they appear in the file.
  373. .SS "Diff \-f Output Format"
  374. .P
  375. With the
  376. .BR \-f
  377. option, an alternative format of script shall be produced. It is
  378. similar to that produced by
  379. .BR \-e ,
  380. with the following differences:
  381. .IP " 1." 4
  382. It is expressed in reverse sequence; the output of
  383. .BR \-e
  384. orders changes from the end of the file to the beginning; the
  385. .BR \-f
  386. from beginning to end.
  387. .IP " 2." 4
  388. The command form <\fIlines\fP> <\fIcommand-letter\fR> used by
  389. .BR \-e
  390. is reversed. For example, 10\fIc\fP with
  391. .BR \-e
  392. would be
  393. .IR c 10
  394. with
  395. .BR \-f .
  396. .IP " 3." 4
  397. The form used for ranges of line numbers is
  398. <space>-separated,
  399. rather than
  400. <comma>-separated.
  401. .SS "Diff \-c or \-C Output Format"
  402. .P
  403. With the
  404. .BR \-c
  405. or
  406. .BR \-C
  407. option, the output format shall consist of affected lines along with
  408. surrounding lines of context. The affected lines shall show which ones
  409. need to be deleted or changed in
  410. .IR file1 ,
  411. and those added from
  412. .IR file2 .
  413. With the
  414. .BR \-c
  415. option, three lines of context, if available, shall be written before
  416. and after the affected lines. With the
  417. .BR \-C
  418. option, the user can specify how many lines of context are written.
  419. The exact format follows.
  420. .P
  421. The name and last modification time of each file shall be output in the
  422. following format:
  423. .sp
  424. .RS 4
  425. .nf
  426. "*** %s %s\en", \fIfile1\fR, <\fIfile1 timestamp\fR>
  427. "--- %s %s\en", \fIfile2\fR, <\fIfile2 timestamp\fR>
  428. .fi
  429. .P
  430. .RE
  431. .P
  432. Each <\fIfile\fP> field shall be the pathname of the corresponding
  433. file being compared. The pathname written for standard input is
  434. unspecified.
  435. .P
  436. In the POSIX locale, each <\fItimestamp\fP> field shall be equivalent
  437. to the output from the following command:
  438. .sp
  439. .RS 4
  440. .nf
  441. date "+%a %b %e %T %Y"
  442. .fi
  443. .P
  444. .RE
  445. .P
  446. without the trailing
  447. <newline>,
  448. executed at the time of last modification of the corresponding file (or
  449. the current time, if the file is standard input).
  450. .P
  451. Then, the following output formats shall be applied for every set of
  452. changes.
  453. .P
  454. First, a line shall be written in the following format:
  455. .sp
  456. .RS 4
  457. .nf
  458. "***************\en"
  459. .fi
  460. .P
  461. .RE
  462. .P
  463. Next, the range of lines in
  464. .IR file1
  465. shall be written in the following format if the range contains
  466. two or more lines:
  467. .sp
  468. .RS 4
  469. .nf
  470. "*** %d,%d ****\en", <\fIbeginning line number\fR>, <\fIending line number\fR>
  471. .fi
  472. .P
  473. .RE
  474. .P
  475. and the following format otherwise:
  476. .sp
  477. .RS 4
  478. .nf
  479. "*** %d ****\en", <\fIending line number\fR>
  480. .fi
  481. .P
  482. .RE
  483. .P
  484. The ending line number of an empty range shall be the number of the
  485. preceding line, or 0 if the range is at the start of the file.
  486. .P
  487. Next, the affected lines along with lines of context (unaffected lines)
  488. shall be written. Unaffected lines shall be written in the following
  489. format:
  490. .sp
  491. .RS 4
  492. .nf
  493. " %s", <\fIunaffected_line\fR>
  494. .fi
  495. .P
  496. .RE
  497. .P
  498. Deleted lines shall be written as:
  499. .sp
  500. .RS 4
  501. .nf
  502. "- %s", <\fIdeleted_line\fR>
  503. .fi
  504. .P
  505. .RE
  506. .P
  507. Changed lines shall be written as:
  508. .sp
  509. .RS 4
  510. .nf
  511. "! %s", <\fIchanged_line\fR>
  512. .fi
  513. .P
  514. .RE
  515. .P
  516. Next, the range of lines in
  517. .IR file2
  518. shall be written in the following format if the range contains two
  519. or more lines:
  520. .sp
  521. .RS 4
  522. .nf
  523. "--- %d,%d ----\en", <\fIbeginning line number\fR>, <\fIending line number\fR>
  524. .fi
  525. .P
  526. .RE
  527. .P
  528. and the following format otherwise:
  529. .sp
  530. .RS 4
  531. .nf
  532. "--- %d ----\en", <\fIending line number\fR>
  533. .fi
  534. .P
  535. .RE
  536. .P
  537. Then, lines of context and changed lines shall be written as described in
  538. the previous formats. Lines added from
  539. .IR file2
  540. shall be written in the following format:
  541. .sp
  542. .RS 4
  543. .nf
  544. "+ %s", <\fIadded_line\fR>
  545. .fi
  546. .P
  547. .RE
  548. .SS "Diff \-u or \-U Output Format"
  549. .P
  550. The
  551. .BR \-u
  552. or
  553. .BR \-U
  554. options behave like the
  555. .BR \-c
  556. or
  557. .BR \-C
  558. options, except that the context lines are not repeated; instead,
  559. the context, deleted, and added lines are shown together, interleaved.
  560. The exact format follows.
  561. .P
  562. The name and last modification time of each file shall be output
  563. in the following format:
  564. .sp
  565. .RS 4
  566. .nf
  567. "--- %s\et%s%s %s\en", file1, <file1 timestamp>, <file1 frac>, <file1 zone>
  568. "+++ %s\et%s%s %s\en", file2, <file2 timestamp>, <file2 frac>, <file2 zone>
  569. .fi
  570. .P
  571. .RE
  572. .P
  573. Each <\fIfile\fR> field shall be the pathname of the corresponding file
  574. being compared, or the single character
  575. .BR '\-'
  576. if standard input is being compared. However, if the pathname contains
  577. a
  578. <tab>
  579. or a
  580. <newline>,
  581. or if it does not consist entirely of characters taken
  582. from the portable character set, the behavior is implementation-defined.
  583. .P
  584. Each <\fItimestamp\fR> field shall be equivalent to the output from the
  585. following command:
  586. .sp
  587. .RS 4
  588. .nf
  589. date \(aq+%Y-%m-%d %H:%M:%S\(aq
  590. .fi
  591. .P
  592. .RE
  593. .P
  594. without the trailing
  595. <newline>,
  596. executed at the time of last modification of the corresponding file
  597. (or the current time, if the file is standard input).
  598. .P
  599. Each <\fIfrac\fR> field shall be either empty, or a decimal point
  600. followed by at least one decimal digit, indicating the
  601. fractional-seconds part (if any) of the file timestamp. The
  602. number of fractional digits shall be at least the number needed to
  603. represent the file's timestamp without loss of information.
  604. .P
  605. Each <\fIzone\fR> field shall be of the form
  606. .BR \(dqshhmm\(dq ,
  607. where
  608. .BR \(dqshh\(dq
  609. is a signed two-digit decimal number in the range \-24 through +25, and
  610. .BR \(dqmm\(dq
  611. is an unsigned two-digit decimal number in the range 00 through 59.
  612. It represents the timezone of the timestamp as the number of hours
  613. (hh) and minutes (mm) east (+) or west (\-) of UTC for the timestamp.
  614. If the hours and minutes are both zero, the sign shall be
  615. .BR '+' .
  616. However, if the timezone is not an integral number of minutes away
  617. from UTC, the <\fIzone\fR> field is implementation-defined.
  618. .P
  619. Then, the following output formats shall be applied for every set
  620. of changes.
  621. .P
  622. First, the range of lines in each file shall be written in the
  623. following format:
  624. .sp
  625. .RS 4
  626. .nf
  627. "@@ -%s +%s @@", <file1 range>, <file2 range>
  628. .fi
  629. .P
  630. .RE
  631. .P
  632. Each <\fIrange\fR> field shall be of the form:
  633. .sp
  634. .RS 4
  635. .nf
  636. "%1d", <beginning line number>
  637. .fi
  638. .P
  639. .RE
  640. .P
  641. or:
  642. .sp
  643. .RS 4
  644. .nf
  645. "%1d,1", <beginning line number>
  646. .fi
  647. .P
  648. .RE
  649. .P
  650. if the range contains exactly one line, and:
  651. .sp
  652. .RS 4
  653. .nf
  654. "%1d,%1d", <beginning line number>, <number of lines>
  655. .fi
  656. .P
  657. .RE
  658. .P
  659. otherwise. If a range is empty, its beginning line number shall be
  660. the number of the line just before the range, or 0 if the empty
  661. range starts the file.
  662. .P
  663. Next, the affected lines along with lines of context shall be written.
  664. Each non-empty unaffected line shall be written in the following format:
  665. .sp
  666. .RS 4
  667. .nf
  668. " %s", <unaffected_line>
  669. .fi
  670. .P
  671. .RE
  672. .P
  673. where the contents of the unaffected line shall be taken from
  674. .IR file1 .
  675. It is implementation-defined whether an empty unaffected line is written
  676. as an empty line or a line containing a single
  677. <space>
  678. character. This line also represents the same line of
  679. .IR file2 ,
  680. even though
  681. .IR file2 's
  682. line may contain different contents due to the
  683. .BR \-b .
  684. Deleted lines shall be written as:
  685. .sp
  686. .RS 4
  687. .nf
  688. "-%s", <deleted_line>
  689. .fi
  690. .P
  691. .RE
  692. .P
  693. Added lines shall be written as:
  694. .sp
  695. .RS 4
  696. .nf
  697. "+%s", <added_line>
  698. .fi
  699. .P
  700. .RE
  701. .P
  702. The order of lines written shall be the same as that of the
  703. corresponding file. A deleted line shall never be written
  704. immediately after an added line.
  705. .P
  706. If
  707. .BR \-U
  708. .IR n
  709. is specified, the output shall contain no more than 2\c
  710. .IR n
  711. consecutive unaffected lines; and if the output contains an
  712. affected line and this line is adjacent to up to
  713. .IR n
  714. consecutive unaffected lines in the corresponding file, the output shall
  715. contain these unaffected lines.
  716. .BR \-u
  717. shall act like
  718. .BR \-U 3.
  719. .SH STDERR
  720. The standard error shall be used only for diagnostic messages.
  721. .SH "OUTPUT FILES"
  722. None.
  723. .SH "EXTENDED DESCRIPTION"
  724. None.
  725. .SH "EXIT STATUS"
  726. The following exit values shall be returned:
  727. .IP "\00" 6
  728. No differences were found.
  729. .IP "\01" 6
  730. Differences were found.
  731. .IP >1 6
  732. An error occurred.
  733. .SH "CONSEQUENCES OF ERRORS"
  734. Default.
  735. .LP
  736. .IR "The following sections are informative."
  737. .SH "APPLICATION USAGE"
  738. If lines at the end of a file are changed and other lines are added,
  739. .IR diff
  740. output may show this as a delete and add, as a change, or as a change
  741. and add;
  742. .IR diff
  743. is not expected to know which happened and users should not care about
  744. the difference in output as long as it clearly shows the differences
  745. between the files.
  746. .SH EXAMPLES
  747. If
  748. .BR dir1
  749. is a directory containing a directory named
  750. .BR x ,
  751. .BR dir2
  752. is a directory containing a directory named
  753. .BR x ,
  754. .BR dir1/x
  755. and
  756. .BR dir2/x
  757. both contain files named
  758. .BR date.out ,
  759. and
  760. .BR dir2/x
  761. contains a file named
  762. .BR y ,
  763. the command:
  764. .sp
  765. .RS 4
  766. .nf
  767. diff -r dir1 dir2
  768. .fi
  769. .P
  770. .RE
  771. .P
  772. could produce output similar to:
  773. .sp
  774. .RS 4
  775. .nf
  776. Common subdirectories: dir1/x and dir2/x
  777. Only in dir2/x: y
  778. diff -r dir1/x/date.out dir2/x/date.out
  779. 1c1
  780. < Mon Jul 2 13:12:16 PDT 1990
  781. ---
  782. > Tue Jun 19 21:41:39 PDT 1990
  783. .fi
  784. .P
  785. .RE
  786. .SH RATIONALE
  787. The
  788. .BR \-h
  789. option was omitted because it was insufficiently specified and does not
  790. add to applications portability.
  791. .P
  792. Historical implementations employ algorithms that do not always produce
  793. a minimum list of differences; the current language about making every
  794. effort is the best this volume of POSIX.1\(hy2017 can do, as there is no metric that could be
  795. employed to judge the quality of implementations against any and all
  796. file contents. The statement ``This list should be minimal'' clearly
  797. implies that implementations are not expected to provide the following
  798. output when comparing two 100-line files that differ in only one
  799. character on a single line:
  800. .sp
  801. .RS 4
  802. .nf
  803. 1,100c1,100
  804. all 100 lines from file1 preceded with "< "
  805. ---
  806. all 100 lines from file2 preceded with "> "
  807. .fi
  808. .P
  809. .RE
  810. .P
  811. The ``Only in'' messages required when the
  812. .BR \-r
  813. option is specified are not used by most historical implementations if
  814. the
  815. .BR \-e
  816. option is also specified. It is required here because it provides
  817. useful information that must be provided to update a target directory
  818. hierarchy to match a source hierarchy. The ``Common subdirectories''
  819. messages are written by System V and 4.3 BSD when the
  820. .BR \-r
  821. option is specified. They are allowed here but are not required because
  822. they are reporting on something that is the same, not reporting a
  823. difference, and are not needed to update a target hierarchy.
  824. .P
  825. The
  826. .BR \-c
  827. option, which writes output in a format using lines of context, has
  828. been included. The format is useful for a variety of reasons, among
  829. them being much improved readability and the ability to understand
  830. difference changes when the target file has line numbers that differ
  831. from another similar, but slightly different, copy. The
  832. .IR patch
  833. utility is most valuable when working with difference listings using
  834. a context format. The BSD version of
  835. .BR \-c
  836. takes an optional argument specifying the amount of context. Rather
  837. than overloading
  838. .BR \-c
  839. and breaking the Utility Syntax Guidelines for
  840. .IR diff ,
  841. the standard developers decided to add a separate option for specifying
  842. a context diff with a specified amount of context (\c
  843. .BR \-C ).
  844. Also, the format for context
  845. .IR diff s
  846. was extended slightly in 4.3 BSD to allow multiple changes that are
  847. within context lines from each other to be merged together. The output
  848. format contains an additional four
  849. <asterisk>
  850. characters after the range of affected lines in the first filename. This
  851. was to provide a flag for old programs (like old versions of
  852. .IR patch )
  853. that only understand the old context format. The version of context
  854. described here does not require that multiple changes within context
  855. lines be merged, but it does not prohibit it either. The extension is
  856. upwards-compatible, so any vendors that wish to retain the old version
  857. of
  858. .IR diff
  859. can do so by adding the extra four
  860. <asterisk>
  861. characters (that is, utilities that currently use
  862. .IR diff
  863. and understand the new merged format will also understand the old
  864. unmerged format, but not \fIvice versa\fP).
  865. .P
  866. The
  867. .BR \-u
  868. and
  869. .BR \-U
  870. options of GNU
  871. .IR diff
  872. have been included. Their output format, designed by Wayne Davison,
  873. takes up less space than
  874. .BR \-c
  875. and
  876. .BR \-C
  877. format, and in many cases is easier to read. The format's timestamps
  878. do not vary by locale, so
  879. .IR LC_TIME
  880. does not affect it. The format's line numbers are rendered with the
  881. .BR %1d
  882. format, not
  883. .BR %d ,
  884. because the file format notation rules would allow extra
  885. <blank>
  886. characters to appear around the numbers.
  887. .P
  888. The substitute command was added as an additional format for the
  889. .BR \-e
  890. option. This was added to provide implementations with a way to fix the
  891. classic ``dot alone on a line'' bug present in many versions of
  892. .IR diff .
  893. Since many implementations have fixed this bug, the standard developers
  894. decided not to standardize broken behavior, but rather to provide the
  895. necessary tool for fixing the bug. One way to fix this bug is to output
  896. two periods whenever a lone period is needed, then terminate the append
  897. command with a period, and then use the substitute command to convert
  898. the two periods into one period.
  899. .P
  900. The BSD-derived
  901. .BR \-r
  902. option was added to provide a mechanism for using
  903. .IR diff
  904. to compare two file system trees. This behavior is useful, is standard
  905. practice on all BSD-derived systems, and is not easily reproducible
  906. with the
  907. .IR find
  908. utility.
  909. .P
  910. The requirement that
  911. .IR diff
  912. not compare files in some circumstances, even though they have the same
  913. name, is based on the actual output of historical implementations.
  914. The specified behavior precludes the problems arising from running
  915. into FIFOs and other files that would cause
  916. .IR diff
  917. to hang waiting for input with no indication to the user that
  918. .IR diff
  919. was hung. An earlier version of this standard specified the output
  920. format more precisely, but in practice this requirement was widely
  921. ignored and the benefit of standardization seemed small, so it is now
  922. unspecified. In most common usage,
  923. .IR diff
  924. .BR \-r
  925. should indicate differences in the file hierarchies, not the difference
  926. of contents of devices pointed to by the hierarchies.
  927. .P
  928. Many early implementations of
  929. .IR diff
  930. require seekable files. Since the System Interfaces volume of POSIX.1\(hy2017 supports named pipes, the
  931. standard developers decided that such a restriction was unreasonable.
  932. Note also that the allowed filename
  933. .BR \-
  934. almost always refers to a pipe.
  935. .P
  936. No directory search order is specified for
  937. .IR diff .
  938. The historical ordering is, in fact, not optimal, in that it prints out
  939. all of the differences at the current level, including the statements
  940. about all common subdirectories before recursing into those
  941. subdirectories.
  942. .P
  943. The message:
  944. .sp
  945. .RS 4
  946. .nf
  947. "diff %s %s %s\en", <\fIdiff_options\fP>, <\fIfilename1\fP>, <\fIfilename2\fP>
  948. .fi
  949. .P
  950. .RE
  951. .P
  952. does not vary by locale because it is the representation of a command,
  953. not an English sentence.
  954. .SH "FUTURE DIRECTIONS"
  955. None.
  956. .SH "SEE ALSO"
  957. .IR "\fIcmp\fR\^",
  958. .IR "\fIcomm\fR\^",
  959. .IR "\fIed\fR\^",
  960. .IR "\fIfind\fR\^"
  961. .P
  962. The Base Definitions volume of POSIX.1\(hy2017,
  963. .IR "Chapter 8" ", " "Environment Variables",
  964. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  965. .\"
  966. .SH COPYRIGHT
  967. Portions of this text are reprinted and reproduced in electronic form
  968. from IEEE Std 1003.1-2017, Standard for Information Technology
  969. -- Portable Operating System Interface (POSIX), The Open Group Base
  970. Specifications Issue 7, 2018 Edition,
  971. Copyright (C) 2018 by the Institute of
  972. Electrical and Electronics Engineers, Inc and The Open Group.
  973. In the event of any discrepancy between this version and the original IEEE and
  974. The Open Group Standard, the original IEEE and The Open Group Standard
  975. is the referee document. The original Standard can be obtained online at
  976. http://www.opengroup.org/unix/online.html .
  977. .PP
  978. Any typographical or formatting errors that appear
  979. in this page are most likely
  980. to have been introduced during the conversion of the source files to
  981. man page format. To report such errors, see
  982. https://www.kernel.org/doc/man-pages/reporting_bugs.html .