LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   What is 'diff' telling me? (https://www.linuxquestions.org/questions/linux-software-2/what-is-diff-telling-me-945223/)

wh33t 05-16-2012 01:39 AM

What is 'diff' telling me?
 
Hey LQ,

Simple question here from a newbie.

I'm trying to use the program 'diff' to tell me if two files aren't the same. I don't really care what the differences are, I just want to know if they are different.

I have created two files.

file1.txt has the word "w00te" in it.
file2.txt has the word "w00t" in it.

So when I run my command this is the output I get.

Code:

wh33t@wh33tserv:~/test_dir/source_dir$ diff file1.txt file2.txt
1c1
< w00te
---
> w00t

So what I want to know is:

1. What does "1c1" mean?
2. If the files are the same will 'diff' always return nothing?
3. Is this the fastest and easiest way to check if two files are the same (remember I don't care what the differences are.

Thanks in Advance!

kbp 05-16-2012 02:20 AM

1. Quoting wikipedia:
Quote:

In this traditional output format, a stands for added, d for deleted and c for changed. Line numbers of the original file appear before a/d/c and those of the modified file appear after. Angle brackets (at the beginning of lines that are added, deleted or changed) indicate which file the lines appear in. Addition lines are added to the original file to appear in the new file. Deletion lines are deleted from the original file to be missing in the new file.
2. Yes

3. You could also use:
Code:

cmp -s file1 file2
.. which does a byte by byte comparison, just check the return code. Diff has more capabilities such as ignoring white space changes and so on, it really depends on your definition of different.

wh33t 05-16-2012 02:27 AM

Quote:

Originally Posted by kbp (Post 4679635)
1. Quoting wikipedia:


2. Yes

3. You could also use:
Code:

cmp -s file1 file2
.. which does a byte by byte comparison, just check the return code. Diff has more capabilities such as ignoring white space changes and so on, it really depends on your definition of different.

Awesome! I will be running this from the system() function in a PHP script. I figure this will save me from having to write or use someone elses PHP script to do diff! Thank you for your help!

+rep.


All times are GMT -5. The time now is 04:46 PM.