You are not logged in.

#1 2014-04-09 02:15:25

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

[Solved] Using diff for directory compare

I'm interested in using diff specifically to verify data integrity; that is, to make sure each file in dirA is data-identical to the corresponding file in dirB. I'm pretty sure it does that, I just want to verify it's not 'assuming identical' if size and timestamps are the same. Thanks.

Last edited by alphaniner (2014-04-09 13:17:16)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#2 2014-04-09 02:39:12

vkumar
Member
Registered: 2008-10-06
Posts: 166

Re: [Solved] Using diff for directory compare

A short test indicates that diff -r should do what you want.


div curl F = 0

Offline

#3 2014-04-09 03:11:57

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [Solved] Using diff for directory compare

The '-r' is definitely necessary, I use diff -rq <dir> <dir> .  I want to confirm file contents are actually compared if they appear to be identical.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#4 2014-04-09 12:08:48

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [Solved] Using diff for directory compare

Testing with 'touch' suggests it does what you want:

% cat foo/foo
hello
% cat bar/foo
hell0
% touch -t 201301011234.20 foo/foo
% touch -t 201301011234.20 bar/foo
% diff -qr foo bar
Files foo/foo and bar/foo differ

Offline

#5 2014-04-09 12:16:08

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: [Solved] Using diff for directory compare

Wait, no, that wasn't a sufficient test. Again with only one invocation of 'touch' so the change times are the same:

% touch -amt 201301011234.20 foo/foo bar/foo
% stat bar/foo foo/foo                       
  File: 'bar/foo'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fe01h/65025d	Inode: 341815      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   trent)   Gid: (  100/   users)
Access: 2013-01-01 12:34:20.000000000 -0500
Modify: 2013-01-01 12:34:20.000000000 -0500
Change: 2014-04-09 08:18:44.000000000 -0400
 Birth: -
  File: 'foo/foo'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: fe01h/65025d	Inode: 341873      Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/   trent)   Gid: (  100/   users)
Access: 2013-01-01 12:34:20.000000000 -0500
Modify: 2013-01-01 12:34:20.000000000 -0500
Change: 2014-04-09 08:18:44.000000000 -0400
 Birth: -
% diff -qr foo bar
Files foo/foo and bar/foo differ

Last edited by Trent (2014-04-09 12:16:40)

Offline

#6 2014-04-09 13:17:04

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: [Solved] Using diff for directory compare

I did the first 'touch test' too, and I *think* it is actually sufficient. But as you pointed out the ctimes are different so I wasn't sure. I couldn't figure out how to make them identical, so thanks.

For the record, everything seems to indicate diff does what I want, but it wasn't explicit. And it was [or seemed] so much faster than verifying dirB with a md5 checksum hash of dirA, it didn't seem like it could actually be reading the files.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#7 2014-04-09 19:35:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] Using diff for directory compare

info diff wrote:

   If two file names are given and both are directories, `diff'
compares corresponding files in both directories, in alphabetical
order; this comparison is not recursive unless the `--recursive' (`-r')
option is given.  `diff' never compares the actual contents of a
directory as if it were a file.  The file that is fully specified may
not be standard input, because standard input is nameless and the
notion of "file with the same name" does not apply.

Offline

Board footer

Powered by FluxBB