Command Line Basics: Compare Files With diff

April 21, 2011 by
Filed under: command line, HowTo, linux, Ubuntu 

In my job as a mechanical engineer, I work with large text files for finite element analysis models. I sometimes have to run several iterations to evaluate different design proposals and I need to check my models against the baseline to make sure that only the intended changes are included. The tool I use to compare files is diff.

diff is a simple yet powerful command line tool. The basic functionality can be invoked like this:

diff file1 file2

By default, diff displays its output vertically, so part of the first file will be shown followed by the difference from the second file. There is however an option to show the differences side by side. You do this by activating the -y switch. You may need to expand your terminal window to make the results truly show side by side.

diff -y file1 file2

For more information about diff, check the man page or Info document.

Affiliate Link
man diff
info diff

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>