LinuxCommandLibrary

colordiff

Display diff output with color highlighting

TLDR

Compare files

$ colordiff [file1] [file2]
copy

Output in two columns
$ colordiff -y [file1] [file2]
copy

Ignore case differences in file contents
$ colordiff -i [file1] [file2]
copy

Report when two files are the same
$ colordiff -s [file1] [file2]
copy

Ignore whitespace
$ colordiff -w [file1] [file2]
copy

SYNOPSIS

colordiff [colordiff_options] [diff_options] file1 file2
colordiff [colordiff_options] -R directory1 directory2
or often used as a pager:
diff options files | colordiff

PARAMETERS

All diff options
    colordiff passes all supplied command-line arguments directly to the underlying diff command.
Therefore, any option valid for diff is also valid for colordiff.

-u, --unified
    Output in unified diff format (common and recommended for readability).

-c, --context
    Output in context diff format (another common format).

-r, --recursive
    Recursively compare any subdirectories found in the specified paths.

-y, --side-by-side
    Output in two columns, which can be combined with -W to set the output width.

--help
    Display the help message for the underlying diff command.

--version
    Display colordiff's version information, and often the version of the underlying diff utility.

DESCRIPTION

The colordiff command is a Perl script designed to colorize the output of the standard diff utility.
It acts as a wrapper around diff, automatically piping its output through an ANSI colorizer.
This significantly improves readability by visually distinguishing between added lines, deleted lines, and changed lines, as well as highlighting differences within lines (e.g., using different colors for characters that are unique to one version).
While diff itself provides line-by-line comparison, colordiff enhances this by applying pre-defined color schemes, making it easier to spot discrepancies at a glance.
Users can customize these color schemes via a configuration file, allowing for personalized visual feedback.
It's particularly useful when reviewing large code changes, configuration file differences, or any textual data where understanding modifications quickly is crucial.
Essentially, it's diff, but much easier on the eyes in a terminal environment.

CAVEATS

As a wrapper script, colordiff relies on the standard diff utility being installed and accessible in the system's PATH.
The colored output is based on ANSI escape codes, which are primarily designed for terminal display.
If redirecting colordiff's output to a file, these escape codes will be included, making the file unreadable unless viewed with a color-aware pager or stripped of codes.
While highly customizable, effective use often requires a good understanding of diff's various output formats to optimize readability.

<B>CONFIGURATION</B>

colordiff allows extensive customization of its color schemes through a user-specific configuration file, typically located at ~/.colordiffrc.
This file uses a simple key-value pair format to define colors for added lines, deleted lines, changed lines, and more, providing granular control over the visual output.

<B>INTEGRATION WITH PAGERS</B>

For viewing large diffs, colordiff is often piped to a pager like less (e.g., diff -u file1 file2 | colordiff | less -R).
The -R or --RAW-CONTROL-CHARS option in less is crucial as it allows less to interpret the ANSI color escape sequences, preserving the colorized output.

HISTORY

colordiff was created by Gavin Young in the early 2000s to provide colorized output for the standard diff command, addressing a common need for improved readability in terminal environments.
It's a standalone Perl script that gained popularity due to its simplicity and effectiveness, filling a gap left by the core diff utility which by default outputs plain text.
It's not part of the GNU diffutils but is widely available as a separate package in most Linux distributions and BSD systems, often installed via package managers like apt, yum, or dnf.
Its development has been steady, focusing on compatibility with various diff versions and improving color customization options via its configuration file.
Its continued usage highlights the enduring value of enhancing command-line tools for better user experience.

SEE ALSO

diff(1), patch(1), grep(1), less(1), wdiff(1), vimdiff

Copied to clipboard