From dfcd5ffaba02555d571cd2e2c4f0cc592d368eab Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Wed, 5 Jul 2023 18:56:39 +1200 Subject: [PATCH] Base: Update diff(1) man page to latest set of options Describe how to use the two new context and unified format options in the diff utility. Also change the example comparison of two files so they contain more lines as that is much more interesting (and useful). --- Base/usr/share/man/man1/diff.md | 41 +++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/Base/usr/share/man/man1/diff.md b/Base/usr/share/man/man1/diff.md index 1f63b75ff2..000c79348d 100644 --- a/Base/usr/share/man/man1/diff.md +++ b/Base/usr/share/man/man1/diff.md @@ -5,7 +5,7 @@ diff - compare files line by line ## Synopsis ```**sh -$ diff [files...] +$ diff [options...] [files...] ``` ## Description @@ -16,16 +16,39 @@ Compare `files` line by line. * `files`: files to compare ex: `file1 file2` +## Options + +* `-u`, `-U `, `--unified `: Write diff in unified format with `` number of surrounding context lines (default 3). +* `-c`, `-C `, `--context `: Write diff in context format with `` number of surrounding context lines (default 3). + ## Examples +First we create two files to compare: + ```sh -# View differences in two files -$ echo 123 > file1 -$ echo 456 > file2 -$ diff file1 file2 -1c1 -< 123 ---- -> 456 +$ printf '1\n2\n3\n' > file1 +$ printf '1\nb\n3\n' > file2 ``` +Here's how to view differences between the two files in normal format: + +```sh +$ diff file1 file2 +2c2 +< 2 +--- +> b +``` + +Here's how to view differences between the two files in unified format: + +```sh +$ diff -u file1 file2 +--- file1 ++++ file2 +@@ -1,3 +1,3 @@ + 1 +-2 ++b + 3 +```