APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/11/19 diff

© November 2003 Tony Lawrence

File comparison, and patch file creator.

Let's say we have two files, t1 and t2


A simple "diff t1 t2" produces:

> defghij

The actual output may not be important to you if all you want to know is if they are different. If they are, $? will be 1 after this, and 0 otherwise. So:

cp t1 t3
diff t1 t3 > /dev/null || echo "t1 and t3 are different"
diff t1 t3 > /dev/null && echo "t1 and t3 are not different"
diff t1 t2 > /dev/null || echo "t1 and t2 are different"
diff t1 t2 > /dev/null && echo "t1 and t2 are not different"

works as expected.

When looking at a diff file, simply remember that everything you see is relative to the FIRST file argument, and that "<" is taking away from it, while ">" is adding to it.

However, there are other arguments you can give to diff that will produce different output. "diff -e" puts out actual instructions you could feed to "ed" to change file1 into file2. "diff -c" produces output that can be fed to "patch" for the same purpose (use the older version of the file as the first argument after -c).

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> diff

Inexpensive and informative Apple related e-books:

Take control of Apple TV, Second Edition

Take Control of High Sierra

Take Control of Automating Your Mac

Photos: A Take Control Crash Course

Take Control of OS X Server

More Articles by © Tony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

Just because they've sold you an IP based phone system doesn't mean they know anything about IP, does it? (Tony Lawrence)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode