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 [OPTION]... [--] FILE1 [FILE2] | DIRECTORY1 DIRECTORY2

PARAMETERS

--help
    Display usage help and exit

--version
    Output version information and exit

--diff-program=PROG
    Use specified diff binary instead of default

--style=NAME
    Apply color style (e.g., cdiff, github, github-dark)

--color=WHEN
    Colorize output: auto (default), always, never

--light
    Force light terminal background colors

--dark
    Force dark terminal background colors

--pairs
    Colorize filename pairs in headers

--basename
    Strip directory names from file headers

--format
    Enable unified-style coloring for context diffs

--tabsize=NUM
    Set tab width for alignment (default 8)

--encoding=ENC
    Specify input encoding for filenames

DESCRIPTION

colordiff is a Perl-based wrapper script around the standard Unix diff utility that adds syntax highlighting with ANSI color codes to make file differences more readable. It highlights added lines in green, removed lines in red, and modified sections in yellow or blue, depending on the configuration. This visual enhancement is invaluable for developers, sysadmins, and anyone reviewing patches, logs, or configuration changes.

colordiff supports all standard diff options by passing them transparently to the underlying diff program, while providing additional features like customizable color schemes, light/dark mode detection, and style presets (e.g., GitHub-like). Output is terminal-aware: colors are enabled by default on interactive terminals but can be forced or disabled.

Common use cases include colordiff file1 file2 for two-file comparisons, colordiff -u old new for unified diffs, or piping git diff | colordiff. It requires a color-capable terminal (most modern ones) and is available via package managers: apt install colordiff on Debian/Ubuntu, yum install colordiff on RHEL.

Customization occurs via config files or environment variables like COLORTERM or CLICOLOR, allowing theme tweaks without altering core behavior.

CAVEATS

Colors require ANSI-supporting terminals; use less -R or most for paging to preserve them. Non-interactive output defaults to no color. May conflict with some pagers or scripts expecting plain diff output.

CONFIGURATION FILES

Customize colors in ~/.colordiffrc or /etc/colordiff/colordiffrc. Example: plain=0;34 for blue unchanged lines.
Environment vars: COLOR_DIFF (style), CLICOLOR (enable/disable).

PIPING USAGE

Ideal for git diff | colordiff | less -R or svn diff | colordiff. Supports --side-by-side via diff -y.

HISTORY

Originally developed by Michael Jennings in 2002 as a Perl script to enhance diff readability. Maintained in Linux distributions since ~2005 (Debian package). Evolved with support for modern terminals, Git integration, and themes; latest versions (1.0.20+) include dark mode and extended styles.

SEE ALSO

diff(1), vimdiff(1), diffstat(1), grep(1)

Copied to clipboard