
interdiff Command in Linux
The interdiff command in Linux displays the difference between two patch files. Essentially, it compares the changes introduced by one patch file against another and shows their differences. It is particularly useful when managing multiple patches or assessing how one patch alters another.
The interdiff command generates a unified diff. Both patches must refer to the same base files, and to ensure accuracy, it's recommended that each diff includes at least three lines of context.
Table of Contents
Here is a comprehensive guide to the options available with the interdiff command −
- Prerequisites to Use interdiff Command
- Syntax of interdiff Command
- interdiff Command Options
- Examples of interdiff Command in Linux
Prerequisites to Use interdiff Command
By default, the interdiff command may not be available in all Linux distributions. To use the interdiff command, it needs to be installed. To check whether it is installed or not, use the following command −
interdiff --version

If the above command shows the version, it means the interdiff command is installed. If no output is shown, then use the following instructions to install it.
The interdiff command is part of the patchutils suite. The patchutils suite offers various command-line utilities to work with patches.
To install the patchutils package on Ubuntu, Kali Linux, Raspberry Pi OS, Debian, and other Debian-based distributions, use the following command −
sudo apt install patchutils
To install it on Arch Linux, use −
sudo pacman -S patchutils
To install the patchutils package on CentOS, use the following command −
sudo yum install patchutils
To install it on Fedora, use the following command −
sudo dnf install patchutils
Syntax of interdiff Command
The syntax of the interdiff command is as follows −
interdiff [options] [patch1] [patch2]
The [options] field is used to specify the options to modify the commandâs behavior. The [patch1] and [patch2] files are used to specify the diff files.
interdiff Command Options
The options for the interdiff command are listed below −
Flag | Option | Description |
---|---|---|
-p n | --strip-match=n | To strip n leading directory components from file paths before comparing them |
-q | --quiet | To suppress rationale lines at the start of each patch for quieter output |
-U n | --unified=n | To display n lines of the context (requires n lines of context in both files) |
-d pattern | --drop-context=pattern | To ignore that context on files that match the specified pattern |
-i | --ignore-case | To ignore the case sensitivity |
-w | --ignore-all-space | To ignore the white-space changes in the patch files |
-b | --ignore-space-change | To ignore changes in the amount of whitespace but does not ignore the presence of whitespace |
-B | --ignore-blank-lines | To ignore blank lines in the patch files |
-z | --decompress | To decompress files with .gz and .bz2 extensions |
--interpolate | To tell the command to run in its default mode, which is the standard interdiff behavior | |
--combine | To switch the command to operate in combinediff mode | |
--no-revert-omitted | To prevent changes from being reverted when a file is modified by the first patch but not by the second | |
--help | To display help with the command | |
--version | To display the commandâs version |
Examples of interdiff Command in Linux
This section demonstrates how to use the interdiff command in Linux with examples −
- Comparing Two Patch Files
- Displaying the Specified Number of Context Lines
- Reversing the Patch
- Ignoring the Whitespace Changes in the Patch Files
- Comparing the Compressed Patch Files
- Comparing the Case Difference
- Dropping Context Lines
- Displaying Help
Comparing Two Patch Files
To compare two patch files, use the interdiff command in the following way −
interdiff pfile1.patch pfile2.patch

Displaying the Specified Number of Context Lines
To display the specific number of context lines, use the -U or --unified option. For example, to display two lines of context, use the interdiff command in the following manner −
interdiff -U 2 pfile1.patch pfile2.patch
Reversing the Patch
To reverse the patch, compare it against /dev/null. It will essentially undo the changes made by the patch file.
interdiff pfile1.patch /dev/null

Ignoring the Whitespace Changes in the Patch Files
To compare two patches but ignore differences in whitespace (such as spaces or tabs), use the -w or --ignore-all-space option −
interdiff -w pfile1.patch pfile2.patch
Comparing the Compressed Patch Files
To compare compressed patch files, use the -z or --decompress options with the interdiff command −
interdiff -z pfile1.patch.gz pfile2.patch.gz

Comparing the Case Difference
To ignore the case difference while comparing two patch files, use the -i or --ignore-case option −
interdiff -i pfile1.patch.gz pfile2.patch.gz
Dropping Context Lines
To drop context lines for specific files from the output, use the -d or --drop-context option with a pattern.
interdiff -d â*.txtâ pfile1.patch pfile2.patch
This option drops context lines matching the specified pattern, where the pattern can include shell wildcards such as * and ?, but slashes (/) or periods (.) are not treated as special characters.
Displaying Help
To display help related to the interdiff command, use the --help option −
interdiff --help
Conclusion
The interdiff command in Linux is a handy tool for comparing two patch files. By generating a unified diff format, interdiff allows for the examination of changes, making it especially useful for developers managing multiple patches or needing to track modifications over time.
To reverse patches, compare compressed files, or drop context for specific files, the interdiff command provides the functionality necessary for efficient patch analysis.
In this tutorial, we explained the interdiff command, including its installation, syntax, options, and usage in Linux with examples.