What are common diff options?

0139

Here are some common options for the diff command that are frequently used:

  1. -u: Unified format output, which shows a few lines of context around the differences.

    diff -u file1.txt file2.txt
  2. -c: Context format output, providing more context around the differences than the default output.

    diff -c file1.txt file2.txt
  3. -r: Recursively compare directories and their contents.

    diff -r dir1 dir2
  4. -i: Ignore case differences in the file contents.

    diff -i file1.txt file2.txt
  5. -w: Ignore all white space when comparing lines.

    diff -w file1.txt file2.txt
  6. -q: Report only whether the files differ, without showing the actual differences.

    diff -q file1.txt file2.txt
  7. -y: Display the differences side by side.

    diff -y file1.txt file2.txt
  8. --suppress-common-lines: When used with -y, this option suppresses lines that are the same in both files.

    diff -y --suppress-common-lines file1.txt file2.txt

These options can be combined to customize the output according to your needs. For example:

diff -urN dir1 dir2

This command will recursively compare dir1 and dir2, treating absent files as empty and providing a unified output format.

0 Comments

no data
Be the first to share your comment!