Re: Program to compare two directory trees

From: Larry I Smith (larryXiXsmith_at_verizon.net)
Date: 09/25/04


Date: Sat, 25 Sep 2004 01:24:41 GMT

Peter Ammon wrote:
> Norm Dresner wrote:
>
>> "James Antill" <james-netnews@and.org> wrote in message
>> news:pan.2004.09.24.17.57.29.757033@and.org...
>>
>>> On Thu, 23 Sep 2004 19:21:41 +0000, Norm Dresner wrote:
>>>
>>>
>>>> In the distant past I wrote my own program to recursively traverse two
>>>> parallel directory trees (each at arbitrary depth from the root) and
>>
>>
>> list
>>
>>>> the differences between them. The program used (IIRC) stat() to get
>>
>>
>> file
>>
>>>> sizes and dates and printed a line on the output for each mismatch.
>>>>
>>>> I find myself needing something like this again, but this time I don't
>>
>>
>> care
>>
>>>> about the sizes or dates, just the (non-)existence of the files.
>>>> Before
>>
>>
>> I
>>
>>>> reinvent the wheel, is there a (pseudo) standard utility available that
>>
>>
>> will
>>
>>>> do this. I'm less likely to make stupid errors that would
>>>> invalidate my
>>>> explorations if I can use a pre-tested program than if I have to study
>>
>>
>> and
>>
>>>> try to understand code I wrote over a decade ago.
>>>
>>>
>>> diff -qru <dir> <dir>
>>
>>
>>
>> Yeah, several people have pointed out that modern versions of diff
>> will do
>> that. The original program was written back in the '80s for a VAX
>> running a
>> UNIX-like OS. Ah, progress ...
>>
>> Thanks to all who answered.
>>
>> Norm
>
>
> Sorry, I don't see the original response, which is why I'm replying
> here. My second reaction to this was diff as well, but won't diff
> report differences in the files' contents, not merely the existence of
> the files? The OP appears to want different files with the same name to
> be considered the same, and AFAIK diff cannot do that.
>
> My first reaction was to use find to enumerate the directory contents in
> each directory, and then diff to compare them.
>
> -Peter

Diff has many options. Several cause it to merely say that
a file differs in the two dirs, or that a file is only in one
of the dirs. Given none of these options, it will display
the diffs of the file contents. Here's one possible example:

   diff --brief --recursive dir1 dir2

See 'info diff' for additional options (there are about 50
options available).

Regards,
Larry

-- 
Anti-spam address, change each 'X' to '.' to reply directly.


Relevant Pages

  • Re: how to compare permissions between two dirs
    ... is there any way to compare two diff dirs and see if they only ... A grasshopper walks into a bar and the bartender says "Hey, ...
    (freebsd-questions)
  • Re: Program to compare two directory trees
    ... My second reaction to this was diff as well, ... > report differences in the files' contents, ... of the dirs. ...
    (comp.unix.shell)
  • Re: Program to compare two directory trees
    ... My second reaction to this was diff as well, ... > report differences in the files' contents, ... of the dirs. ...
    (comp.os.linux.development.apps)
  • Re: try to recursively compare two folders (File::dircmp)
    ... By default it lists the files that are only in dir1, the files only in dir2, and for the files that are common to both dirs, whether they are identical or not. ... "diff" means, for the differing files, actually show the differing contents, not just the filename. ... "suppress" means don't bother listing filenames that are identical in both dirs. ...
    (comp.lang.perl.misc)
  • Re: Program to compare two directory trees
    ... several people have pointed out that modern versions of diff will do ... The original program was written back in the '80s for a VAX running a ... My second reaction to this was diff as well, ...
    (comp.unix.programmer)