How to colorize diff on the command line?

colordiff side-by-side
command line diff tool
diff command
diff-highlight
color diff online
colordiff command not found
git diff color
man diff

When I have a diff, how can I colorize it so that it looks good? I want it for the command line, so please no GUI solutions.

How to color diff output?, If the lines are too narrow (default 80 columns), fit to screen with: diff You can, for example, colorize the output of the diff command just by typing your usual  diff Command Colorize Output On the Unix / Linux Command Line colordiff is a wrapper for diff and produces the same output as diff but with coloured syntax highlighting at the command line to improve readability. colordiff has been tested on various flavours of Linux and under OpenBSD, but should be broadly portable to other systems.

Use Vim:

diff /path/to/a /path/to/b | vim -R -

Or better still, VimDiff (or vim -d, which is shorter to type) will show differences between two, three or four files side-by-side.

Examples:
vim -d /path/to/[ab]

vimdiff file1 file2 file3 file4

diff within a line, On desktop, meld can highlight the differences within a line for you. 48. For color, install colordiff, then do: wdiff a b | colordiff – philfreo Sep 28 '13 at 3:36 git diff -U0 --word-diff --no-index -- foo bar | grep -v ^@@ On the command line, I would make sure I add judicious new-lines before comparing files. diff --color option was added to GNU diffutils 3.4 (2016-08-08) This is the default diff implementation on most distros, which will soon be getting it. Ubuntu 18.04 has diffutils 3.6.

Actually there seems to be yet another option (which I only noticed recently, when running into the problem described above):

git diff --no-index <file1> <file2>
# output to console instead of opening a pager
git --no-pager diff --no-index <file1> <file2>

If you have Git around (which you already might be using anyway), then you will be able to use it for comparison, even if the files themselves are not under version control. If not enabled for you by default, then enabling color support here seems to be considerably easier than some of the previously mentioned workarounds.

diff Command Colorize Output On the Unix / Linux Command Line , colordiff is a wrapper for diff and produces the same output as diff but with coloured syntax highlighting at the command line to improve readability  You probably already know that Git can colorize its diff output, and you can even customize the colors yourself. However, there are also scripts that filter Git's output and change it even further. For instance, there's a diff-highlight script that puts an extra emphasis on the changed part of a line.

colordiff - a tool to colorize diff output, colordiff is a wrapper for diff and produces the same output as diff but with coloured syntax highlighting at the command line to improve readability. The output is  The .bat code below demonstrates (1) the use of inline color codes, (2) the color failure that can occur when inline color codes are used in a FOR loop or within a parenthesized block of code, and (3) a solution to the problem.

And for those occasions when a yum install colordiff or an apt-get install colordiff is not an option due to some insane constraint beyond your immediate control, or you're just feeling crazy, you can re-invent the wheel with a line of sed:

sed 's/^-/\x1b[41m-/;s/^+/\x1b[42m+/;s/^@/\x1b[34m@/;s/$/\x1b[0m/'

Throw that in a shell script and pipe unified diff output through it.

It makes hunk markers blue and highlights new/old filenames and added/removed lines in green and red background, respectively.1 And it will make trailing space2 changes more readily apparent than colordiff can.


1 Incidentally, the reason for highlighting the filenames the same as the modified lines is that to correctly differentiate between the filenames and the modified lines requires properly parsing the diff format, which is not something to tackle with a regex. Highlighting them the same works "well enough" visually and makes the problem trivial. That said, there are some interesting subtleties.

2 But not trailing tabs. Apparently tabs don't get their background set, at least in my xterm. It does make tab vs space changes stand out a bit though.

colordiff, About colordiff. The Perl script colordiff is a wrapper for 'diff' and produces the same output but with pretty 'syntax' highlighting. Colour schemes can be  The -e option tells diff to output a script, which can be used by the editing programs ed or ex, that contains a sequence of commands. The commands are a combination of c (change), a (add), and d (delete) which, when executed by the editor, will modify the contents of file1 (the first file specified on the diff command line) so that it matches

Diff with colour highlighting Using diff, svn diff ARGUMENTS_FOR_DIFF | source-highlight --out-format=esc The best command line collection on the internet, submit yours and save your is named ccze, on redhat based systems I think its called colorize. The windows equivalent to the diff command is the fc (File Comapre) command. Here are the basic steps to do so: 1. Keep the two files in a folder (Example file1.html and file2.html) 2. Launch command prompt 3. Type fc file1Location file2Location . Have found a detailed tutorial on the same:

Linux Basics: colordiff, An Alternative To The diff Command, color-diff is available in the default repositories of Ubuntu, so the apt-get command-line tool can help me to install it in my own system. Type the  There'd be 9 green bottles standing on the wall. You can create a file by following these instructions: Open the file by typing the following command: nano file2. Type the text into the nano editor. Press CTRL and O to save the file. Press CTRL and X to exit the file.

icdiff: side-by-side highlighted command line diffs, Your terminal can display color, but most diff tools don't make good use of it. By highlighting changes, icdiff can show you the differences between similar files  diff Command Colorize Output On the Unix / Linux Command Line colordiff is a wrapper for diff and produces the same output as diff but with coloured syntax highlighting at the command line to improve readability. colordiff has been tested on various flavours of Linux and under OpenBSD, but should be broadly portable to other systems.

Comments
  • Any particular operating system/shell?
  • Try github.com/walles/riff. As an added bonus, it highlights what parts of the lines that changed.
  • a GUI solution: superuser.com/a/431000/370203
  • Just found that myself :-). It can be piped into less by using less -R, which displays the escape sequences for colors correctly.
  • Can just use the syntax: colordiff file1 file2
  • Alas, it doesn't work for the side-by-side output (-y option to enable) ☹ The vimdiff suggestion below probably a better way
  • colordiff works well for svn diff | colordiff (i.e. in situations where you only have the diff, not the two files being diffed).
  • As an update to @Hi-Angel 's comment: colordiff has been updated and now includes side by side (-y) support.
  • function ddiff(){ diff $1 $2 | vim -R - } export -f ddiff
  • @Jichao: I prefer to learn the commands rather than alias them away. That way I can use them anywhere, even when my dotfiles aren't available.
  • @AquariusPower: ctrl-c and ctrl-x have other uses in Vim. ctrl-q is captured by many terminals. See Writing and quitting to find the way that best suits your needs.
  • First, what kind of shell is this? zsh? I don't recognize =(...) construct. Second, I had diff -ur a b in mind.
  • Indeed. In Zsh, a command of the form =(...) is replaced with the name of a file containing its output.
  • This is neat, but sadly this doesn't work when the inputs are pipes. For example comparing binary files via git diff <(xxd file1) <(xxd filed) doesn't work.