LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-16-2012, 02:39 AM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 800

Rep: Reputation: 58
Question 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!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-16-2012, 03:20 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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.
 
2 members found this post helpful.
Old 05-16-2012, 03:27 AM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 800

Original Poster
Rep: Reputation: 58
Quote:
Originally Posted by kbp View Post
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.
 
  


Reply

Tags
diff, return nothing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setting git-diff --color-words as git-diff potuz Linux - Software 5 09-09-2010 02:31 PM
What is this Firewall telling?? aq_mishu Linux - Security 3 11-15-2007 07:31 PM
Just telling everyone who I am Thedrew87 LinuxQuestions.org Member Intro 1 10-01-2006 05:26 PM
Dual Boot diff Hard Disk diff OS on Suse 9.1 wilhem Linux - Newbie 1 08-13-2004 07:06 PM
what is this error telling me? cadkins Linux - Newbie 1 03-19-2004 12:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration