Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Tech198

Cancelled
Original poster
Mar 21, 2011
15,915
2,151
I'm trying to tell what diff does in Terminal, but all i can find is it compares directories and/or files..

What i'm interested to know is "how" it compares ? File size, AND time stamp (can be excluded some of these) ?

I'm only interested in filenames and filsizes only,, not time stamp info. so i'm not sure if diff would still flag inaccurate creation.. or weather this can be exuded....

I've already come down to using diff -r and optional q on main folder will scan ALL sub directories within, which is exactly what i'm wanting, but there is no point in using the command if you can't exclude bits and pieces..
 

MisterSavage

macrumors 601
Nov 10, 2018
4,769
5,643
I use diff to compare the contents of different text files. I don't think that timestamp is a factor.

To test I create file1 and file2 that contain the same text but have different creation times. A 'diff file1 file2' returns nothing, which is what I expected.
 

Tech198

Cancelled
Original poster
Mar 21, 2011
15,915
2,151
Yes, i already looked at the flags.

I did a test as well and it looks like it only picks uo different based on file name only... not size..

To test, i created two directory, with same text file name in each "Untitled"

I then edited one of then adding more text,to increase bytes size... but kept same file name..

I then ran diff -r passing two directories in Terminal and it didn't come out with any differences. If dff cannot compare file sizes as well as filename differences then its not gonna work for me.

As for comparison, i understood diff would out differences in filename AND file size.. otherwise i would either need to resort to utilities, or just go into each and every folder which takes time..

Ideally i'm using diff on main dir in two different locations, so it will go into all sub-folders 3 or more levels deep

Perhaps diff is not the best use case for this ?
 

MisterSavage

macrumors 601
Nov 10, 2018
4,769
5,643
Was your test something like this? It's working for me.

$ diff -r one/one.txt two/one.txt

2a3,4

>

> new lines.
 

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,090
4,718
This^^^.

Also working here.

Code:
>> mkdir f1
>> echo "this is text" > f1/f1.txt
>> echo "this is file 2" > f1/f2.txt
>> ls f1
f1.txt    f2.txt
>> cp -r f1 f2
>> ls f2
f1.txt    f2.txt
>> diff -r f1 f2
>> echo "new text" > f2/f2.txt
>> echo "new file" > f2/f3.txt
>> ls f2
f1.txt    f2.txt    f3.txt
>> diff -r f1 f2
diff -r f1/f2.txt f2/f2.txt
1c1
< this is file 2
---
> new text
Only in f2: f3.txt
>> diff -rq f1 f2
Files f1/f2.txt and f2/f2.txt differ
Only in f2: f3.txt
>> diff -r -q f1 f2
Files f1/f2.txt and f2/f2.txt differ
Only in f2: f3.txt
>>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.